【问题标题】:Uploading image to s3 using multer-imager使用 multer-imager 将图像上传到 s3
【发布时间】:2018-11-14 04:17:20
【问题描述】:

我正在尝试通过一些图像预处理(如宽度、高度等)将图像上传到 s3 存储桶。我的代码如下

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',
    signatureVersion: 'v4',
    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!');
 }); 

输出如下

上传成功!

但文件大小是“零”

【问题讨论】:

标签: node.js express


【解决方案1】:

同时设置裁剪。

gm: {                                 
    width: 360,                        
    height: 700,
    format: 'png',                      
    **crop: {
      width: 1000,
      height: 1000,
      x: 0,
      y: 0,
    },**
 },

并尝试去掉选项中的!,看看两张图片的区别。

【讨论】:

    猜你喜欢
    • 2017-05-22
    • 2017-03-22
    • 2021-04-04
    • 2021-06-10
    • 2021-02-04
    • 2021-04-16
    • 2018-01-01
    • 1970-01-01
    • 2019-10-26
    相关资源
    最近更新 更多