取得图片网址时发生ECONNRESET错误

时间:2018-10-09 09:33:04

标签: node.js amazon-s3 request http-post

当我尝试将相机图像上传到AWS Bucket时,将出现以下错误:

camera upload error {"errno":"ECONNRESET","code":"ECONNRESET","syscall":"read"}
{ Error: read ECONNRESET
at TCP.onread (net.js:622:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 
'read' }

实际上,该图像将能够从Heroku和我的本地计算机上载。当我尝试从生产环境中尝试时,会出现上述错误。以下是我用于将图像上传到AWS存储桶的代码片段:

 var request = require("request");
 var moment = require('moment-timezone'),
 var AWS = require('aws-sdk');
 AWS.config.update({
 accessKeyId: accessKeyId,
 secretAccessKey: secretAccessKey
 });
 var requestretry = require('requestretry');
 var s3 = new AWS.S3(),
 s3Stream = require('s3-upload-stream')(new AWS.S3());

 var date = moment().unix();
 var options = {
 method: 'GET',
 url: image_url
 };
 var d = Date.now();
 var upload = s3Stream.upload({
 Bucket: 'twilio-voice-clip/voice',
 Key: 'cameraimage' + d + '.jpeg',
 ACL: 'public-read',
 ContentType: 'image/jpeg'
 });


 request(options)
 .on('response', function (response) {
    if (response.statusCode != 200) {
        console.log(respDetails);
    }
   })
 .on('error', function (err) {
    console.log('camera upload error', JSON.stringify(err));

  })
 .pipe(upload)
 .on('uploaded', function (details) {
    console.log(details.Location);
 });

0 个答案:

没有答案