s3-forklift
aws-sdk based kinda high level s3 / spaces (Digital Ocean) uploader. It wraps upload method of aws-sdk. For file upload, ContentType
automatically added. Also, it can remove uploaded file from the file system, after upload completed successfully.
Install
npm install s3-forklift --save
Test
Rename secret.example.json
to secret.json
with valid credentials.
Then, run test via npm run test
Requirements
- Node.js 10+
Initialize
const Forklift = ; // Initialize;const forklift = cloud: "<CLOUD_NAME>" // do or aws accessKey: "<YOUR_ACCESS_KEY>" secretKey: "<YOUR_SECRET_KEY>" bucket: "<BUCKET_NAME>" region: "<REGION>" // optional, default: "us-east-1" s3params: ACL: "bucket-owner-read" // optional, default: {ACL: "public-read"};
Upload
source
should be string (file path) or readable stream.remotePath
s3 path.options
Besides the all the options of original S3.upload you can pass{remove: true}
to remove the source after upload completed successfully{timestamp: true}
to add timestamp at the end of url
const url = await forklift;
Example
// To upload file// ContentType automatically retrieved from file name and passed to S3.upload method// if you want to override it, you should pass {ContentType:"<CONTENT_TYPE>"} as options.const url = await forklift; // To upload and then remove the file with callbackconst url = await forklift; // To upload a stream without ContentTypeconst url = await forklift; // To upload a stream with ContentTypeconst url = await forklift;