file-upload-s3
v0.1.5
Published
> An aws s3 image upload package, comes with image compression if you so choose to use this feature
Readme
AWS S3 IMAGE UPLOAD
An aws s3 image upload package, comes with image compression if you so choose to use this feature
Note: This package is in no way endorsed by AWS, but is a little pet project of mine i wish to make big one day
Install
npm i file-upload-s3yarn add file-upload-s3How to use
const express = require('express');
const formidable = require('formidable');
....
const AWS = require('file-upload-s3');
const upload = new AWS.Upload({
access: '',
secret: '',
region: '',
bucket: ''
});
......
app.post('/upload', async (req, res) => {
let form = new formidable.IncomingForm();
form.parse(req, async function(err, fields, files) {
if (err) {
console.error(err.message);
return;
}
const img = await upload.uploadFile(files.image, false, true) // (a, b, c)
// a = 'image to be uploaded'
// b = 'bucket name if you haven't provided it in the initialization earlier
// c = 'compress, if true, the image would be compressed before sent off to aws s3,
false, the image won't be compressed'
res.json(img)
});
})
Dev Server
npm run startyarn startProduction Bundle
npm run buildyarn build