我目前正在使用 Skipper S3 将图像保存到 S3 存储桶中npm 模块通过 Sails JS 。
我使用船长保存到 s3 存储桶的代码
如下:
req.file('imageName').upload({
saveAs: 'FileName.png',
adapter: require('skipper-s3'),
key: 'key',
secret: 'secret',
bucket: 'bucketName'
}, function whenDone(err, uploadedFiles) {
if (err)
//error handling
else
// return back the Image URl into S3.
});
目前我正在遵循此 link 中给出的方法.这种方法效率不高,并且随图像大小而变化。
我的要求是将图像(.png.jpg,.tif,.gif)
调整为3个不同的尺寸(80* 80,100*120 和 130*270)。我想将我的初始图像和3调整大小的图像同时保存到S3 Bucket
中。但我无法通过 req.file 提取给定图像的缓冲区。
我在 Stack Overflow 上提到了以下问题,但无法从他们那里得到答案。
- Skipper in SailsJS (beta) image resize before upload
- Uploading multiple files with Sails.js 0.10 and Skipper using Dropzone.js
- Sails.js File upload with Skipper to AWS S3
有人可以帮忙吗?
最佳答案
您可以将图像大小调整过程从您的应用程序分离到 AWS Lambda。一旦您的图像刚刚上传到 S3 存储桶,AWS Lambda 函数就会被触发。 AWS 提供了调整图像大小的简单演练:Handling Amazon S3 Events Using the AWS CLI (Node.js) .
关于node.js - 在上传到 S3 存储桶之前将给定图像调整为 3 种不同的尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32431560/