I have a form where you can upload a file. I upload the file directly with skipper and it works perfectly.
req.file('file').upload({
adapter: require('skipper-s3'),
key: 'key',
secret: 'secret',
bucket: 'bucketname'
}, function (err, uploadedFiles) {
if (err){
// ko
}
else{
// ok
}
});
But I want to resize first and then upload the file, so:
sharp(original).resize(800).quality(90).toBuffer(function(err, outputBuffer) {
if (err) {
// ko
}
// ok
outputBuffer;
});
So, my question is: How can upload the outputBuffer
instead of req.file('file')
?
Instead of using
skipper-s3
you can use the aws-sdk module. Upload the image to disk (original), process it, upload it, and delete the original.Alternatively, some libraries (like gm) can take a remote URL. You could use skipper-s3 to upload, then carry out the process above (where original is the s3 URL) and it would work, too—really not performant, at all, though.