Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Node.js 303连接到AWS-SDK时永久重定向_Javascript_Node.js_Amazon Web Services_Amazon S3_Http Status Code 301 - Fatal编程技术网

Javascript Node.js 303连接到AWS-SDK时永久重定向

Javascript Node.js 303连接到AWS-SDK时永久重定向,javascript,node.js,amazon-web-services,amazon-s3,http-status-code-301,Javascript,Node.js,Amazon Web Services,Amazon S3,Http Status Code 301,下午好 我正在尝试建立与aws产品api的连接,但我不断收到301永久重定向错误,如下所示: { [PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.] message: 'The bucket you are attempting

下午好

我正在尝试建立与aws产品api的连接,但我不断收到301永久重定向错误,如下所示:

{ [PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.]
  message: 'The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.',
  code: 'PermanentRedirect',
  name: 'PermanentRedirect',
  statusCode: 301,
  retryable: false }
var aws = require('aws-sdk');

//Setting up the AWS API
aws.config.update({
    accessKeyId: 'KEY',
    secretAccessKey: 'SECRET',
    region: 'eu-west-1'
})

var s3 = new aws.S3();

s3.createBucket({Bucket: 'myBucket'}, function() {
    var params = {Bucket: 'myBucket', Key: 'myKey', Body: 'Hello!'};
    s3.putObject(params, function(err, data) {
        if (err)
            console.log(err)
        else
            console.log("Successfully uploaded data to myBucket/myKey");
    });
});
我用于连接API的代码如下所示:

{ [PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.]
  message: 'The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.',
  code: 'PermanentRedirect',
  name: 'PermanentRedirect',
  statusCode: 301,
  retryable: false }
var aws = require('aws-sdk');

//Setting up the AWS API
aws.config.update({
    accessKeyId: 'KEY',
    secretAccessKey: 'SECRET',
    region: 'eu-west-1'
})

var s3 = new aws.S3();

s3.createBucket({Bucket: 'myBucket'}, function() {
    var params = {Bucket: 'myBucket', Key: 'myKey', Body: 'Hello!'};
    s3.putObject(params, function(err, data) {
        if (err)
            console.log(err)
        else
            console.log("Successfully uploaded data to myBucket/myKey");
    });
});
如果我尝试使用不同的区域,比如us-west-1,我只会得到相同的错误

我做错了什么


提前非常感谢

我已经解决了这个问题:

你必须确保你已经创建了一个同名的bucket;在本例中,bucket的名称将是“myBucket”

s3.createBucket({Bucket: 'myBucket'}, function() {
var params = {Bucket: 'myBucket', Key: 'myKey', Body: 'Hello!'}; 
创建bucket后,转到properties并查看它使用的区域-将其添加到:

aws.config.update({
    accessKeyId: 'KEY',
    secretAccessKey: 'SECRET',
    region: 'eu-west-1'
})

现在应该可以了!最美好的祝愿

我刚刚遇到了这个问题,我相信上面的例子是不正确的

演示代码的问题是Bucket名称应该是小写的-

如果演示程序在s3.createBucket中的回调上实际输出err参数,那么这将是显而易见的

此外,bucket名称在创建它们的区域中必须是唯一的

s3.createBucket({Bucket: 'mylowercaseuniquelynamedtestbucket'}, function(err) {

    if(err){
        console.info(err);
    }else{
        var params = {Bucket: 'mylowercaseuniquelynamedtestbucket', Key: 'testKey', Body: 'Hello!'};
        s3.putObject(params, function(err, data) {
            if (err)
                console.log(err)
            else
                console.log("Successfully uploaded data to testBucket/testKey");
        });
    }

 })

在这件事上被困了一段时间

在我的配置文件中设置区域名称或将其保留为空都无法解决此问题。我遇到了讨论解决方案的要点,非常简单:

鉴于:

var AWS = require('aws-sdk');
在实例化S3对象之前,请执行以下操作:

AWS.config.update({"region": "us-west-2"}) //replacing your region there
然后,我可以毫无问题地拨打以下电话:

var storage = new AWS.S3();
var params = {
                Bucket: config.aws.s3_bucket,
                Key: name,
                ACL:'authenticated-read',
                Body: data
            }
storage.putObject(params, function(storage_err, data){...})

哦,好吧,那么我该如何让它工作呢?或者出了什么问题?这里可能会说明一个显而易见的问题:遵循重定向。然而,这可能是你使用的API的一个缺陷,它没有为你遵循重定向。哇!修好了!问题是我没有在S3控制台中创建任何Bucket!谢谢你,兄弟!Bucket名称必须在所有S3中都是唯一的,而不仅仅是在特定区域。