s3-file

0.0.2 • Public • Published

s3-file

Simple module to manage files (upload, download, delete) on the Amazon S3

Code example

var s3 = require('s3-file')('pathToAWSConfig');
 
s3.upload('./myFilePath.txt', 'fileKey', 'bucket', function (err, metadata) {
  if (err) return console.log(err);
  console.log(metadata);
});

AWS config example

{
  "accessKeyId": "ACCESS_KEY",
  "secretAccessKey": "SECRET_KEY",
  "region": "REGION"
}

API

Upload file

From stream

var stream = fs.createReadStream('./myFilePath.txt');
 
s3.upload(stream, 'fileKey', 'bucket', function (err, metadata) {
  if (err) return console.log(err);
  console.log(metadata);
});

From file path

s3.upload('./myFilePath.txt', 'fileKey', 'bucket', function (err, metadata) {
  if (err) return console.log(err);
  console.log(metadata);
});

Download file

To stream

s3.download('fileKey', 'bucket').toStream(function (err, stream) {
  if (err) return console.log(err);
  console.log('done');
});

To file

s3.download('fileKey', 'bucket').toFile('./myS3file.txt', function (err, stream) {
  if (err) return console.log(err);
  console.log('done');
});

File exists

s3.fileExists('fileKey', 'bucket', function (result) {
  console.log(result);
});

Delete file

s3.deleteFile('fileKey', 'bucket', function (err) {
  if (err) return console.log(err);
  console.log('done');
});

Test

Edit config.json in test folder and fill all fields with your credentials.

npm test

License

MIT

Package Sidebar

Install

npm i s3-file

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • felipe-dev