【问题标题】:looping s3.putObject process only the first 3 requests循环 s3.putObject 仅处理前 3 个请求
【发布时间】:2021-07-18 19:43:30
【问题描述】:

所以,我正在尝试从我的数据库中的 URL 获取和下载流数据。从那里我试图将下载的内容放在一个 s3 存储桶中,但是,在 5 个 URL 中,只有前三个获取过程。这是我的循环代码

const uploadToS3 = async (uploadData) =>{

    for (const file of uploadData){
            const {data, headers} = await axios.get(file.attachment_url, {responseType: 'stream'});
        try {
            console.log(file.attachment_url)
                const objectParams = {
                    Bucket: BUCKET_NAME,
                    Key: 'Resume'+'_'+file.candidate_id+' _ '+file.candidate_first_name,
                    ContentLength: headers['content-length'],
                    Body: data
                };
            await  s3.putObject(objectParams).promise();
        }catch (e){
                console.log(e)
        }

    }
console.log('Finished')

}

有人遇到过这种情况吗?它也会抛出这个我也无法弄清楚的错误。

errorRequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.

我已经检查过了,所有三个 URL 都被传递给了这个函数。它只处理 5 个中的 3 个。

【问题讨论】:

  • 尝试使用upload代替putObject。
  • 你的标题暗示这是关于 s3 但你确定不是 GET 请求失败了吗?
  • @404 不,我仔细检查了我是否从每个 URL 获取数据,确实是。
  • @404 原来是 S3 的重复密钥问题。它正在覆盖重复的名称键。
  • @Mu-Majid 原来是 S3 的重复密钥问题。它正在覆盖重复的名称键。

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


【解决方案1】:

我不知道您要上传的文件的大小,但putObject 主要用于上传小文件,如果文件很大,您可能会收到超时错误。

尝试改用upload(),因为它在后台为您处理了很多功能,例如多部分上传。

【讨论】:

    【解决方案2】:

    所以它实际上是 objectParams 键的问题。由于它们是相同 ID 的 URL,因此 aws s3 跳过了具有相同密钥的 URL。例如

     Key: 'Resume'+'_'+file.candidate_id+'_'+file.attachment_filename,
    

    具有相同键名的那些(这是我缺少的那个)。 AWS 正在跳过它们或不覆盖已经上传的那些。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-29
      • 1970-01-01
      • 1970-01-01
      • 2013-03-22
      • 2017-12-23
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      相关资源
      最近更新 更多