S3 Client

SaltwaterC edited this page Dec 26, 2012 · 57 revisions

Client loader

aws.load('s3', [accessKeyId], [secretAccessKey])

Available low level methods

The S3 POST method is not fully implemented. Its use case may be replaced by the s3.put(). The POST method doesn't bring any benefit while implementing multipart/form-data into the API implies a lot of overhead for zero benefits. The existing s3.post() low level method is in use by the S3 Multipart API.

Available helpers

S3 Multipart Upload API

Usage mode

var s3 = require('aws2js').load('s3', accessKeyId, secretAccessKey);

All the API specific actions can be made by using the low level methods. The S3 helpers are provided for convenience.

Examples

// creates the foo bucket with private access into the us-east-1 region
s3.createBucket('foo', false, false, function (error, result) {
});

// creates the bar bucket with public-read access into the Northern California region
s3.createBucket('bar', 'public-read', 'us-west-1', function (error, result) {
});

// makes the bar bucket to be private accesible
s3.setBucketAcl('bar', 'private', function (error, result) {
});

// uploads the foo.png file into the foo bucket with public-read access
s3.setBucket('foo');
s3.putFile('foo.png', '/path/to/foo.png', 'public-read', {}, function (error, result) {
});

// uploads the buffer contents as the S3 file contents
s3.setBucket('foo');
s3.putBuffer('foo.txt', new Buffer('bar', 'utf8'), 'public-read', {'content-type': 'text/plain'}, function (error, result) {
});

// uploads the Readable Stream contents as the S3 file contents
s3.setBucket('foo');
var stream = fs.ReadStream('./foo.txt'); // may be any object implementing the Readable Stream interface
s3.putStream('foo.txt', stream, 'public-read', {'content-type': 'text/plain', 'content-length': streamLength}, function (error, result) {
});

// changes the acl to private for an existing bar.jpg object of the bar bucket
s3.setBucket('bar');
s3.setObjectAcl('bar.jpg', 'private', function (error, result) {
});

// changes the object meta data in order to specify the cache control header
s3.setBucket('foo');
s3.setObjectMeta('foo.png', 'public-read', {'cache-control': 'public'}, function (error, result) {
})