【问题标题】:Download files from AWS S3 in Node.js app在 Node.js 应用程序中从 AWS S3 下载文件
【发布时间】:2021-04-21 09:42:04
【问题描述】:

我有一个将文件上传到 AWS S3 存储桶的代码:

var upload = multer({
 storage: multerS3({
     s3: s3,
     bucket: 'mybucketname',
     key: function (req, file, cb) {
          cb(null, Date.now().toString())
     }
   }),
 fileFilter: myfilefiltergeshere...

})

我想下载上传的源代码。我不知道该怎么做,因为我真的不知道如何识别 S3 上的文件。它是上传中的关键字段,还是我必须指定的其他内容?

【问题讨论】:

    标签: node.js amazon-web-services amazon-s3 download


    【解决方案1】:

    可以下载

    import AWS from 'aws-sdk'
    
    AWS.config.update({
      accessKeyId: '....',
      secretAccessKey: '...',
      region: '...'
    })
    
    const s3 = new AWS.S3()
    
    async function download (filename) {
      const { Body } = await s3.getObject({
        Key: filename,
        Bucket: 'mybucketname'
      }).promise()
      return Body
    }
    
    const dataFiles = await Promise.all(files.map(file => download(file)))
    

    我在数组中有文件,这就是我使用files.map 的原因,但我想您可以查看一些指导类型的代码,这可能会对您有所帮助。 更多内容你可以阅读this

    【讨论】:

      猜你喜欢
      • 2017-04-27
      • 1970-01-01
      • 2015-09-16
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2023-04-01
      相关资源
      最近更新 更多