Wednesday, 7 June 2017

Uploading image to s3 using multer-imager

I'm trying to upload image to s3 bucket with some image preprocess like width,height and so on . My code as follows

html

 <form action="/upload" method="POST" enctype="multipart/form-data">
 <input type="file" name="pic" id="pic" class="pic" accept="image/*">
 <input type="submit">
 </form>

nodejs

var s3=new AWS.S3();

var upload = multer({
 storage: imager({
    dirname: 'avatars',
    bucket: 'patientimg',
    accessKeyId: 'xxxxxxxxxx',
    secretAccessKey: 'yyyyyyyyyyy',
    region: 'zzzzzz',
    filename: function (req, file, cb) {  
              cb(null, Date.now())                
     },                                    
     gm: {                                  
      width: 200,                         
      height: 200,
      options: '!',
      format: 'png'                       
     },
    s3 : {                                
    Metadata: {                        
    'acl': 'public-read'              
   }
  }

})
});


 app.post('/upload', upload.array('pic', 1), function(req, res, next){ 
 console.log(req.files); // Print upload details
 res.send('Successfully uploaded!');
 }); 

output as follows

The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.



via V Abinaya

No comments:

Post a Comment