5

我正在尝试在 nodejs 项目中使用 knox 上传到 Amazon s3 存储桶,但无法通过 403 错误。我已确保正确设置了密钥、秘密和存储桶。我真的可以在这里从那些有更多经验的人那里得到一些帮助。

我的节点代码如下:

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

}

4

1 回答 1

3

For future viewers:

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

digitalKarma --> digitalkarma

于 2012-07-16T12:06:28.327 回答