Automattic / knox

S3 Lib
MIT License
1.74k stars 285 forks source link

{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' } #200

Closed alduro closed 10 years ago

alduro commented 11 years ago

Hi there, Maybe this is a kind of duplicate issue but what is weird is that I'm getting it with a particular BUCKET. One bucket works perfect and other bucket from a different AWS account does not. Policies are correct on both buckets. Same for region US Standard. What am I doing wrong ? Thanks in advance.

part of the code is:

awsClient = knox.createClient({
  key: config['AWS_S3']['KEY'],
  secret: config['AWS_S3']['SECRET'],
  bucket: config['AWS_S3']['BUCKET']
});

fileNameTo = ['articles/', req.files.upload.name.replace(' ','_')].join('');
fileNameToURL = ['https://s3.amazonaws.com/',config['AWS_S3']['BUCKET'], 'articles/', req.files.upload.name.replace(' ','_')].join('');
// dest = __dirname + "/../../public/uploads/" + req.files.upload.name;

//  Upload to S3
awsClient.putFile(req.files.upload.path, fileNameTo, {
  'Content-Type': "image/" + type,
  'Cache-Control': 'max-age=155520000, public',
  'Expires': new Date(Date.now() +  155520000000).toUTCString()
}, function(err, result) {
  if (200 == result.statusCode) {
    var html;
    if (err) {
        console.log('key ' + config['AWS_S3']['KEY'] );
        console.log('secret ' + config['AWS_S3']['SECRET'] );
        console.log('bucket ' + config['AWS_S3']['BUCKET'] );
        console.log(err);
        return;
    }
    html = "";
    html += "<script type='text/javascript'>";
    html += "    var funcNum = " + req.query.CKEditorFuncNum + ";";
    html += "    var url     = " + "'" + result.req.url + "'" + ";";
    html += "    var message = \"Uploaded file successfully\";";
    html += "";
    html += "    window.parent.CKEDITOR.tools.callFunction(funcNum, url, message);";
    html += "</script>";

    res.send(html);
  }
});
domenic commented 10 years ago

Um it's hard to say what's going on here. You have one bucket that always works and one bucket that always gives the ECONNRESET error? Can you reproduce this in isolated small programs? Is there something weird about the bucket name for the error-ing one? Or maybe some special character in the key/secret that is in the erroring one but not the OK one?