I need to resize my images before I upload them to s3 (amazon).
I tried this function but it's not working.
Here is the function that uploads the image.
My file name is: beach_life-normal.jpg
I tried this new code but it still doesn't work!!!
This is my code:
var AWS = require('aws-sdk'),
fs = require('fs');
var express = require("express");
var app = express();
var im = require('imagemagick');
// For dev purposes only
AWS.config.update({ accessKeyId: '', secretAccessKey: '' });
// Read in the file, convert it to base64, store to S3
var fileStream = fs.createReadStream('beach_life-normal.jpg');
fileStream.on('error', function (err) {
if (err) { throw err; }
});
fileStream.on('open', function () {
var s3 = new AWS.S3();
im.resize({
srcPath: 'beach_life-normal.jpg',
dstPath: 'beach_life-normal-small.jpg',
width: 256
});
s3.putObject({
Bucket: 'adinoauploadefile',
Key: 'beach_life-normal.jpg',
Body: fileStream
}, function (err) {
if (err) { throw err; }
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…