2014-10-21 8 views
3

노드 AWS SDK를 사용하여 이미지를 s3에 저장하고 있습니다. 나는 버킷이 존재한다는 사실에도 불구하고 다음과 같은 오류가 계속 나는 올바른 권한이 있습니다AWS s3 api 오류 : 지정된 버킷이 없습니다.

{ [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 } 

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

나는 또한 시도했다 siv.io.s3-웹 사이트를 버킷 이름은 -us-east-1.amazonaws.com입니다. 누군가 내가 잘못 가고있는 것을 알려 줄 수 있습니까? 필요한 경우 더 많은 정보를 제공 할 수 있습니다.

답변

5

오류는 버킷이 아직 존재하지 않는다고 말하고 있습니다. 코드를 보면 버킷 이름이 올바르지 않아서 파일을 찾을 수 없습니다. createBucket()으로 전화하거나 AWS 콘솔에서 버킷을 만듭니다.

API 호출을하는 대신 파일을 추가 할 수 있습니다. 무엇을 넣을지는 AWS API docs을 확인하십시오. 그들의 문서는 정말 좋습니다.

는 여기에 내가 할 수있는 작업은 다음과 같습니다

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

네 말이 맞아. 내 버킷 명명 규칙이 잘못되었습니다. 명명 규칙은 정말로 혼란 스럽습니다. 이 [그림] (http://i.imgur.com/rWXOwbg.png)은 나를 위해 효과가 있었던 것을 보여줍니다. – SivaDotRender

관련 문제