node.js - 如何使用nodejs将图像上传到s3时设置到期日期

标签 node.js amazon-s3 aws-sdk-nodejs

我想在nodejs sdk中上传图像/视频并设置到期日期。 谁能告诉我如何在将图像上传到 s3 时设置到期日期?

最佳答案

You can use multer-s3 middleware for express, and then you can configure the headers that you want by providing the Expires, Cache-Control headers.

const upload = multer({
  storage: multerS3({
    s3: s3,
    bucket: 'some-bucket',
    contentType: multerS3.AUTO_CONTENT_TYPE,
    expires: 'Wed, 21 Oct 2020 07:28:00 GMT',
    key: function (req, file, cb) {
      cb(null, Date.now().toString())
    }
  })
})


app.post('/upload', upload.array('photos', 3), function(req, res, next) {
  res.send('Successfully uploaded ' + req.files.length + ' files!')
})

关于node.js - 如何使用nodejs将图像上传到s3时设置到期日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46188908/

相关文章:

node.js - react /Node 未捕获语法错误 : Unexpected token <

Python Boto3 更新/覆盖 S3 存储桶中的对象

amazon-web-services - 用于 NodeJS 的 AWS-SDK : how to get credentials being used in program

amazon-web-services - 如何从 ~/.aws/config 加载配置

javascript - Node js JSON 清理

node.js - Mongoose: ref 自定义字段名称

laravel - 当我尝试安装 composer League/flysystem-aws-s3-v3 时出现错误

javascript - 检查 DynamoDB 表是否包含键并返回 bool 值

arrays - 转储整个数组 : console. 日志和 console.dir 输出 "... NUM more items]"

amazon-web-services - 如何将整个文件夹从 s3 存储桶复制到 ec2 实例