5

I'm trying to upload to an Amazon s3 bucket using knox in a nodejs project but can't get past a 403 error. I've ensured that the key,secret, and bucket are properly set. I could really use some help here from those with more experience.

My node code is as follows:

var upload_test = function(){

var client = knox.createClient(
    {
      key: config.aws.key
    , secret: config.aws.secret
    , bucket: config.aws.bucket
    }
);

fs.readFile('test.pdf', function(err,buf){
    var req = client.put('6530/test.pdf', {
        'Content-length': buf.length,
        'Content-Type': 'application/pdf'
    });
    req.on('response',function(res){
        if(res.statusCode === 200){
            console.log('Success!');
            req.on('data',function(chunk) {
                console.log(chunk);
            });
        }
        else {
            console.log("Error statusCode: " + res.statusCode);
            console.log("URL: " + req.url);
            req.on('data',function(chunk){
                console.log(chunk);
            });
        }
    });
});

}

ben75
  • 29,217
  • 10
  • 88
  • 134
John Ten Cate
  • 475
  • 5
  • 16

1 Answers1

3

For future viewers:

My similar problem was solved by changing my bucket name to all lowercase letters

digitalKarma --> digitalkarma

Nathan Lippi
  • 4,967
  • 5
  • 25
  • 29
  • 1
    In my case, it seemed to be a hyphen in the bucket name. – medmunds Aug 22 '14 at 03:54
  • @medmunds so did it work after removing the hyphen? – Zia Dec 08 '20 at 23:51
  • @Zia yes, it worked fine with all lowercase alpha-only bucket name – medmunds Dec 09 '20 at 03:41
  • @medmunds please can you take a look at a similar question and let me know what I am doing wrong? https://stackoverflow.com/questions/65225966/nodejs-knox-formidable-results-in-a-400-file-not-uploaded-to-s3-bucket Thank you. – Zia Dec 09 '20 at 22:41
  • @Zia I have no idea, sorry. Looks like someone is already trying to help you over there; suggest working through their suggestions carefully one by one. I just commented here—six years ago—to confirm that uppercase letters could cause 403 errors trying to upload to S3, and add that hyphens caused the same symptom. – medmunds Dec 10 '20 at 02:37