带有NodeJS和s3-uploader模块的AWS S3图像上传器 [英] AWS S3 Image Uploader with NodeJS and s3-uploader module
问题描述
我正在尝试使用此模块 https://www.npmjs.com/package/s3-uploader
,但对我来说,如何实现它尚不清楚.如何对路由器执行 POST
?
I am trying to use this module https://www.npmjs.com/package/s3-uploader
but for me it's not clear how to implement it. How to do a POST
to my router ?
.post('/upload', ensureAuthenticated, (req, res, next) => {
let files = req.files;
let client = new Upload(process.env.AWS_BUCKET_NAME, {
aws: {
path: process.env.AWS_BUCKET_PATH,
region: process.env.AWS_BUCKET_REGION,
acl: 'public-read'
},
cleanup: {
versions: true,
original: false
},
original: {
awsImageAcl: 'private'
},
versions: [{
maxHeight: 1040,
maxWidth: 1040,
format: 'jpg',
suffix: '-large',
quality: 80,
awsImageExpires: 31536000,
awsImageMaxAge: 31536000
},{
maxWidth: 780,
aspect: '3:2!h',
suffix: '-medium'
},{
maxWidth: 320,
aspect: '16:9!h',
suffix: '-small'
},{
maxHeight: 100,
aspect: '1:1',
format: 'png',
suffix: '-thumb1'
},{
maxHeight: 250,
maxWidth: 250,
aspect: '1:1',
suffix: '-thumb2'
}]
});
client.upload(files.file.path, {}, function(err, versions, meta) {
if (err) { throw err; }
versions.forEach(function(image) {
console.log(image.width, image.height, image.url);
// 1024 760 https://my-bucket.s3.amazonaws.com/path/110ec58a-a0f2-4ac4-8393-c866d813b8d1.jpg
});
});
}
在 .post
内的
我复制并粘贴了他们在NPM网站中拥有的代码,并将变量值更改为我的值.
inside the .post
I copied and paste the code they have in NPM website and changed the variables values to mine values.
我收到此错误:
Error: Command failed: identify -format "name=
size=%[size]
format=%m
colorspace=%[colorspace]
height=%[height]
width=%[width]
orientation=%[orientation]
" /images/logo.png
/bin/sh: identify: command not found
at ChildProcess.exithandler (child_process.js:206:12)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:877:16)
at Socket.<anonymous> (internal/child_process.js:334:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:498:12)
我在此线程中找到了一个相关但不完全有用的主题: Node.js S3-uploader问题
I found a related but not fully helpful topic in this thread: Node.js S3-uploader issue
推荐答案
以下是解决方案:
我唯一要做的就是在本地主机上安装imagemagick.
The only thing that I did was installing imagemagick on my localhost.
您必须在终端中运行它.
You have to run this in your terminal.
cd $ HOME
酿造imagemagick
完成后,您可以运行它以查看版本和详细信息
When it finish you can run this to see the version and details
brew info imagemagick
如果您没有酿酒
,则需要安装它.
If you dont have brew
then you need to install it.
谢谢
这篇关于带有NodeJS和s3-uploader模块的AWS S3图像上传器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!