I wish to post file to multipart form and upload it to Amazon S3 Bucket and return to user link to the file.
const express = require('express'),
aws = require('aws-sdk'),
bodyParser = require('body-parser'),
multer = require('multer'),
multerS3 = require('multer-s3');
aws.config.update({
secretAccessKey: 'secret',
accessKeyId: 'secret',
region: 'us-east-2'
});
const app = express(),
s3 = new aws.S3();
app.use(bodyParser.json());
const upload = multer({
storage: multerS3({
s3: s3,
bucket: 'some-name',
key: (req, file, cb) => {
console.log(file);
cb(null, file.originalname); //use Date.now() for unique file keys
}
})
});
app.post('/upload', upload.array('file',1), (req, res, next) => {
res.send("How to return File URL?");
});
app.listen(3000);
How can I have the direct URL to the file?
undefined
. – Vashti