1

I'm using an ExpressJS (based on Node.js) to push up to Amazon S3. I'm new to this so, I copied the example Amazon gave, and I see that in the S3 Management Console, there's an extra file that's the same name as the bucket I'm creating. What part of my code made this?

// Create a bucket using bound parameters and put something in it.
var s3bucket = new AWS.S3({params: {Bucket: 'test_bucket/sub_bucket'}});
s3bucket.createBucket(function() {
    var data = {Key: 'result', Body: 'Hello!'};
    s3bucket.putObject(data, function(err, data) {
        if (err) {
            console.log("Error uploading data: ", err);
        } else {
            res.writeHead(200, {'Content-Type':'text/plain'});
            res.write("Successfully uploaded data to test_bucket/sub_bucket/");
            res.end()
        }
    });
});
4

1 回答 1

5

var s3bucket = new AWS.S3({params: {Bucket: 'test_bucket/sub_bucket'}});将创建一个额外的文件。取出括号中的参数。我发现亚马逊的快速入门指南示例创建了一个额外的文件。这种方式是正确的做法。

// Create a bucket using bound parameters and put something in it.
var s3bucket = new AWS.S3();
s3bucket.createBucket(function() {
    var params = {Bucket: 'bucket/sub-bucket', Key: 'file_name1', Body: 'Hello!'};
    s3bucket.putObject(params, function(err, data) {
        if (err) {
            console.log("Error uploading data: ", err);
        } else {
            res.writeHead(200, {'Content-Type':'text/plain'});
            res.write("Successfully uploaded data to bucket/sub-bucket/");
            res.end()
        }
    });
});
于 2013-08-12T21:57:44.193 回答