aws-s3-connector
v0.0.5
Published
Amazon WebService S3 Connector
Downloads
5
Readme
AWS S3 Connector
Tired of all the hassles downloading, removing from and uploading to Amazon S3? The solution is here!
Install
npm install --save aws-s3-connector
Initialize Bucket
- With CoffeeScript
S3Connector = require 'aws-s3-connector'
Storage = new S3Connector
credentials: './credentials/aws.json'
Bucket: 'BUCKET_NAME'
- With JavaScript
var S3Connector = require('aws-s3-connector');
var Storage = new S3Connector({
credentials: './credentials/aws.json',
Bucket: 'BUCKET_NAME'
});
Download File
The Bucket is already defined in the Storage! You only need to pass the folder and filename inside S3 as remoteFile.
download 'remoteFile', 'localFile', callback
# or
download 'remoteFile', Buffer, callback
- With CoffeeScript
Storage.download 'from-nosql/test.json', './downloads/test.json', (err) ->
return console.error err if err
console.log 'file downloaded'
- With JavaScript
Storage.download('from-nosql/test.json', './downloads/test.json', function(err) {
if (err) {
return console.error(err);
}
console.log('file downloaded');
});
Remove File(s)
remove 'remoteFile', callback
# or, to remove multiple files at once
remove ['remoteFile1', 'remoteFile2'], callback
- With CoffeeScript
Storage.remove 'from-nosql/test.json', (err) ->
return console.error err if err
console.log 'file removed'
- With JavaScript
Storage.remove('from-nosql/test.json', function(err) {
if (err) {
return console.error(err);
}
console.log('file removed');
});
Upload File
upload 'localFile', 'remoteFile', callback
# or
upload Buffer, 'remoteFile', callback
- With CoffeeScript
Storage.upload './uploads/answer.json', 'from-kernel/answer.json', (err) ->
return console.error err if err
console.log 'file uploaded'
- With JavaScript
Storage.upload('./uploads/answer.json', 'from-kernel/answer.json', function(err) {
if (err) {
return console.error(err);
}
console.log('file uploaded');
});
Options
- The credentials json should be of the following format:
{
"accessKeyId": "YOUR_ACCESS_KEY_ID",
"secretAccessKey": "YOUR_SECRET_ACCESS_KEY",
"region": "YOUR_REGION"
}