因此,我正试图从数据库中的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个。
我不知道您试图上传的文件的大小,但putObject
主要用于小文件上传,如果大小较大,可能会出现超时错误。
试着使用upload()
,因为它有很多功能可以在后台为您处理,比如多部分上传。
所以它实际上是objectParams键的问题。由于它们是相同ID
的URL,aws s3跳过了那些具有相同密钥的URL。例如
Key: 'Resume'+'_'+file.candidate_id+'_'+file.attachment_filename,
那些有相同密钥名称的(这就是我丢失的那个(。AWS跳过了它们,或者没有覆盖已经上传的内容。