我正在使用以下方法上传到Meteor中的S3存储桶。我收到请求,如果有响应,我将其上传到S3存储桶。我有大约700个这样的网址。我为每个URL执行HTTP GET请求,并尝试上传到S3。主要问题是,在一开始,对于大约150个文件,我得到以下错误:
I20170725-22:22:39.344(2)? An error occured during upload: { [Error:
connect ECONNRESET https://pushmetrics.com:443]
I20170725-22:22:39.344(2)? code: 'ECONNRESET',
I20170725-22:22:39.344(2)? errno: 'ECONNRESET',
I20170725-22:22:39.345(2)? syscall: 'connect',
I20170725-22:22:39.345(2)? address: 'https://pushmetrics.com',
I20170725-22:22:39.345(2)? port: 443
之后它适用于其他文件。只有前150个网址失败。
uploadToS3: (url, headers, connectionId, itemId, itemName, type) => {
return new Promise(function(resolve, reject) {
request.get({
url: url,
headers: headers,
rejectUnauthorized: false,
}, function(error, response, body) {
if (error) {
reject(error);
} else {
// Create S3 service object
var s3 = new AWS.S3();
// bucketName var below crates a "folder" for each item
var bucketName = '/connections/' + connectionId + '/' + type + '/' + itemId + '/';
var params = {
Bucket: Meteor.settings.private.s3.bucket,
Key: bucketName + itemName + '.png',
Body: body,
ContentType: 'image/png',
ACL: 'public-read'
};
s3.upload(params, function (err, data) {
if (err) {
console.log(`Error during upload file ${params.Key} to S3: ${err}"`);
return res.status(500).send(err)
};
let s3Url = data.Location;
resolve(s3Url)
});
}
});
});
},
方法uploadToS3由以下异步方法调用:
uploadItemToS3: async (url, headers, connectionId, itemId, itemName, type) => {
s3Url = await Api.uploadToS3(url, headers, connectionId, itemId, itemName, type);
return s3Url;
}