nodejs knox put to s3 results in a 403

谁说我不能喝 提交于 2021-02-07 07:37:33

问题


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);
            });
        }
    });
});

}


回答1:


For future viewers:

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

digitalKarma --> digitalkarma



来源:https://stackoverflow.com/questions/10951065/nodejs-knox-put-to-s3-results-in-a-403

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!