我希望将文件发布到多部分表单并将其上传到 Amazon S3 存储桶并返回到文件的用户链接。
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);
如何获得文件的直接 URL?