AWS s3 api错误:指定的存储桶不存在

Siv*_*der 6 amazon-s3 amazon-web-services node.js

我正在使用节点AWS SDK将图像保存到s3.尽管存在存储桶并且我具有正确的权限,但我仍然收到以下错误:

{ [NoSuchBucket: The specified bucket does not exist]
  message: 'The specified bucket does not exist',
  code: 'NoSuchBucket',
  time: Tue Oct 21 2014 12:32:50 GMT-0400 (EDT),
  statusCode: 404,
  retryable: false }
Run Code Online (Sandbox Code Playgroud)

我的nodejs代码:

var fs = require('fs');

var AWS = require('aws-sdk'); //AWS library (used to provide temp credectials to a front end user)
AWS.config.loadFromPath('./AWS_credentials.json'); //load aws credentials from the     authentication text file



var s3 = new AWS.S3();

fs.readFile(__dirname + '/image.jpg', function(err, data) {

var params = {
    Bucket: 'https://s3.amazonaws.com/siv.io',
    Key: 'something',
};

s3.putObject(params, function(err, data) {

    if (err) {

        console.log(err);

    } else {
        console.log("Successfully uploaded data to myBucket/myKey");
    }
});
});
Run Code Online (Sandbox Code Playgroud)

我还尝试了siv.io.s3-website-us-east-1.amazonaws.com作为存储桶名称.有人能让我知道我的错吗?如有必要,我可以提供更多信息.

cla*_*lay 7

该错误表明该存在桶尚不存在.根据代码的外观,存储桶名称不正确,这就是无法找到文件的原因.createBucket()在AWS控制台中拨打电话或创建存储桶.

您也可以添加文件,而不仅仅是进行API调用.检查AWS API文档,了解要放在哪里.他们的文档非常好.

这是我做的:

    var stream = fs.createReadStream( 'path/to/file' );
    stream.on( 'error', function( error ) {
      seriesCb( error );
    } );
    //TODO: Other useful options here would be MD5 hash in the `ContentMD5` field,
    s3.putObject( {
      "Bucket": 'siv.io',
      "Key": 'name_of/new_file',
      "ContentType": "application/pdf", //might not apply to you
      "Body": stream
    }, function( s3err, s3results ) {
      if ( s3err ) return console.log('Bad stuff. ' + s3err.toString() );
      console.log( "Saved to S3. uri:" + s3uri);
    } );
Run Code Online (Sandbox Code Playgroud)