Using Node.js to create bucket and push object, extra blank file created?
amazon-s3, express, node.js
Solution
`var s3bucket = new AWS.S3({params: {Bucket: 'test_bucket/sub_bucket'}});` will create an extra file. Take out the params in the parentheses. I found out that Amazon's quick start guide example creates an extra file. This way is the correct way to do it.
// 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()
}
});
});
Problem
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() } }); }); ```