s3-bucket-version
DEPRECATION NOTICE
WARNING: This project has been renamed to s3-bucket-toolkit. Install using npm i --save s3-bucket-toolkit
instead.
https://github.com/cortezcristian/s3-bucket-toolkit
S3 Bucket Version made easy
- Provide Promisified AWS API methods
- Use recommended listObjectsV2
- Paginate or list all items from the bucket
- Upload multiple files
- Delete all Versions and Markers from a particular file
Install
$ npm i s3-bucket-version --save
Configure
const AWSBucket = ; const bucket = accessKeyId: 'your-access-key-here' secretAccessKey: 'your-secret-here' region: 'us-east-1' bucketACL: 'public-read' bucketName: 'my-bucket' pagingDelay: 500 // (optional) set a global delay in between s3 api calls, default: 500ms;
Usage
Get Upload URL
Get upload URL
bucket; /*Result:{ signedUrl: 'https://your-bucket.s3.amazonaws.com/your-dir/test.js?AWSAccessKeyId=...'}*/
Upload File
bucket; /* Result:{ response: { ETag: '"abc.."' }, url: 'https://my-bucket.s3.amazonaws.com/upload-test.txt' }*/
Upload Multiple Files
bucket; /* Result:[ { response: { ETag: '"abc..."', VersionId: '123..' }, url: 'https://your-bucket.s3.amazonaws.com/upload-test-1.txt' },{ response: { ETag: '"def.."', VersionId: '456...' }, url: 'https://your-bucket.s3.amazonaws.com/upload-test-2.txt' } ]*/
List Files
bucket; /*Result:[ { Key: 'upload-test-1.txt', LastModified: 2018-05-04T06:49:48.000Z, ETag: '"abc..."', Size: 44, StorageClass: 'STANDARD' }, { Key: 'upload-test-2.txt', LastModified: 2018-05-04T06:49:49.000Z, ETag: '"def..."', Size: 44, StorageClass: 'STANDARD' }, ...]*/
List Paged Files
Pagination, see more parameters listObjectsV2 docs
bucket
List File Versions
The param Key is being replaced internally in fovor of Prefix, see the docs s3.listObjectVersions
bucket; /*Result:{ Versions: [ { ETag: '"abc..."', Size: 44, StorageClass: 'STANDARD', Key: 'upload-test.txt', VersionId: 'null', IsLatest: true, LastModified: 2018-05-02T12:53:29.000Z, Owner: [Object] } ], DeleteMarkers: []}*/
Delete Files
bucket; /*Result:{ Deleted: [ { Key: 'upload-test.txt' } ], Errors: [] }*/
Delete All Versions from a Single File
Delete all versions for a given file
bucket; /*Result:{ Deleted: [ { Key: 'upload-test.txt', VersionId: 'abc...' } ], Errors: [] }*/
Delete All Markers from a Single File
Delete all Markers for a given file
bucket;
Delete All Versions and Markers from a Single File
Delete all Versions and Markers for a given file
bucket;
Delete Specific Versions from files
bucket; /*Result:{ Deleted: [ { Key: 'upload-test.txt', VersionId: 'abc...' } ], Errors: [] }*/
Get All buckets
Get All buckets for this account
bucket; /*Result:{ Buckets: [ { Name: 'my-bucket', CreationDate: 2018-03-19T17:49:05.000Z } ], Owner: { DisplayName: 'cris', ID: '...' }}*/