我试图通过像宽度,高度等一些图像预处理将图像上传到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!');
});
输出如下
成功上传!
但文件大小为&#34;零&#34;
答案 0 :(得分:0)
也设置作物。
gm: {
width: 360,
height: 700,
format: 'png',
**crop: {
width: 1000,
height: 1000,
x: 0,
y: 0,
},**
},
并尝试删除选项中的!,并查看两张图片之间的区别。