节点JS AWS S3file upload。 如何获得公共URL响应

我正在使用Node SDK将file upload到Amazon S3。

file upload工作正常,但我想获得该文件的公共url发回给客户端。

目前我得到的答复是:

Successfully uploaded data { ETag: '"957cd1a335adf5b4000a5101ec1f52bf"' } 

这是我的代码。 我正在使用一个Node Express服务器,Multer来处理上传。

 app.use(multer({ // https://github.com/expressjs/multer dest: './public/uploads/', limits : { fileSize:100000 }, rename: function (fieldname, filename) { var time = new Date().getTime(); return filename.replace(/\W+/g, '-').toLowerCase() + time; }, onFileUploadData: function (file, data, req, res) { // file : { fieldname, originalname, name, encoding, mimetype, path, extension, size, truncated, buffer } var params = { Bucket: creds.awsBucket, Key: file.name, Body: data, ACL: 'public-read' }; var s3 = new aws.S3() s3.putObject(params, function (perr, pres) { if (perr) { console.log("Error uploading data: ", perr); } else { console.log("Successfully uploaded data", pres); } }); } })); app.post('/upload-image', function(req, res){ if(req.files.file === undefined){ res.send("error, no file chosen"); } }); 

       

网上收集的解决方案 "节点JS AWS S3file upload。 如何获得公共URL响应"