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
});
});
}
inside the .post I copied and paste the code they have in NPM website and changed the variables values to mine values.
I am getting this error:
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)
I found a related but not fully helpful topic in this thread: Node.js S3-uploader issue
Here is the solution:
The only thing that I did was installing imagemagick on my localhost.
You have to run this in your terminal.
cd $HOME
brew install 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.
Thank you