【问题标题】:Upload with dynamic Filename - multer/s3使用动态文件名上传 - multer/s3
【发布时间】:2018-02-14 15:31:25
【问题描述】:

我使用 multer/multer-s3 将 Profilepicture 上传到 Amazon S3。 当我使用与表单中的字段名匹配的静态文件名(如“userPhoto_”)时,上传效果很好。

var upload = multer({
  storage: multerS3({
      s3: s3,
      bucket: '<bucketname>',
      key: function (req, file, cb) {
          cb(null, file.fieldname);
      }
  })
});

router.post('/api/photo', upload.single('userPhoto_123'), function (req,res) {
  res.end("Uploaded!");
});

在我的 .ejs 文件中,我有类似的输入字段

<input class="ui input" type="file" name="userPhoto_<%=person.id%>" />

所以问题是如何将包含 person.id 的 FieldName 传递给 upload.single - 中间件。

谢谢!

【问题讨论】:

  • 只需传递一个隐藏的输入字段,告诉您用户 ID。让处理更容易

标签: javascript amazon-s3 multer multer-s3


【解决方案1】:

将桶值修改为-

req: 是普通的快递请求

bucket: (req, file, cb) => { CB(空,${req.dynamic_name}); };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    • 2019-09-30
    • 2018-08-03
    • 2019-07-31
    • 2019-01-07
    相关资源
    最近更新 更多