...
Code Block | ||
---|---|---|
| ||
const AWS = require('aws-sdk'); AWS.config.update({region: 'us-east-1'}); var s3 = new AWS.S3({httpOptions: { timeout: 2000 }}); /* The following example retrieves an object for an S3 bucket. */ var params = { Bucket: "mybucket", Key: "myfile.jpg" }; s3s3bucket.getObjectputObject(params, function(err, data) { if (err) { console.log(err"Error uploading data: ", err.stack); // an error occurred} else { console.log(data res.writeHead(200, {'Content-Type':'text/plain'}); // successful response /* data = { AcceptRanges: "bytes", ContentLength: 3191, ContentType: "image/jpeg", ETag: "\"6805f2cfc46c0f04559748bb039d69ae\"", LastModified: <Date Representation>, Metadata: { }, TagCount: 2, VersionId: "null" } */ res.write("Successfully uploaded data to bucket/sub-bucket/"); res.end() } }); |
Retrieving an object from Bucket
...
Code Block | ||
---|---|---|
| ||
const AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
var s3 = new AWS.S3({httpOptions: { timeout: 2000 }});
/* The following example retrieves an object for an S3 bucket. */
var params = {
Bucket: "mybucket",
Key: "myfile.jpg"
};
s3.getObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
/*
data = {
AcceptRanges: "bytes",
ContentLength: 3191,
ContentType: "image/jpeg",
ETag: "\"6805f2cfc46c0f04559748bb039d69ae\"",
LastModified: <Date Representation>,
Metadata: {
},
TagCount: 2,
VersionId: "null"
}
*/
});
// Getting object as a stream
var s3 = new AWS.S3({apiVersion: '2006-03-01'});
var params = {Bucket: 'myBucket', Key: 'myImageFile.jpg'};
var file = require('fs').createWriteStream('/path/to/file.jpg');
s3.getObject(params).createReadStream().pipe(file); |
Deleting an object from Bucket
...
Page Properties | ||
---|---|---|
| ||
|