Friday, 2 June 2017

Upload multiple images - NodeJS & Amazon S3

I have been able to set up a process to upload a single image at a time using NodeJS/Express/Amazon S3/ Multer. It works perfectly. I've been trying to change the code to allow users to upload more than one image at a time. So far I have been very unsuccessful. How would I change my code below to allow multiple images to be uploaded at once? Thanks!

aws.config.update({
    secretAccessKey: '*****************',
    accessKeyId: '******',
    region: 'us-east-2'
});

var s3 = new aws.S3();


var upload = multer({
    storage: multerS3({
        s3: s3,
        bucket: 'myfiles',
        key: function (req, file, cb) {
            var fileExtension = file.originalname.split(".")[1];
            var path = "uploads/" + req.user._id + Date.now() + "." + fileExtension;
            cb(null, path); 
        }
    })
});


router.post("/", upload.array('image', 1), function(req, res, next){

      var filepath = undefined;

    if(req.files[0]) {
        filepath = req.files[0].key;
    }......



via AndrewLeonardi

No comments:

Post a Comment