s3-upload-by-readstream
v1.0.1
Published
This is easy to use readStream upload your file to your AWS S3
Downloads
3
Readme
Description
This module can easy to use readStream upload file to Your AWS S3.
This module use the AWS official SDK.
Installation
npm install s3-upload-by-readstream
Usage
const S3 = require('s3-upload-by-readstream');
let s3client = new S3(
`Your_BucketName`,
`Your region`,
`Your AWS access key ID`,
`Your AWS secret access key`,
S3OptionObject
);
Upload Your File or any Data by ReadStream
use s3client.uploadFile
description
Will upload your file by ReadStream.
parameter:
- upload_path {string} : The file will upload to this path.
- filename {string} : Just filename.
- mimeType {string} : MIME type. ex:application/json
- data {readStream or any} : Your need to upload Data.
- ACL {string} : was same as AWS S3 ACL.
- callback {function} : when upload finish will call and return three parameter :
- RSerror : was same as ReadStream Error. see nodejs document
- S3error {Error}: was same as API AWS_S3.uploadFile error Msg. see AWS S3 Official Doc.
- data {Object}: was same as api AWS_S3.uploadFile Data. see AWS S3 Official Doc.
//Example 1: use other ReadStream upload
const fs = require('fs');
const fsRS = fs.createReadStream(`yourfile.json`));
s3client.uploadFile(
`Your_Bucket_TargetPath`,
`myJson.json`,
`application/json`,
fsRS,
`public-read`,
(rsErr, S3err, data)=>{
//other code...
});
//Example 2: will Auto use ReadStrem upload
s3client.uploadFile(
`Your_Bucket_TargetPath`,
`myJson.json`,
`application/json`,
JSON.stringify({"example": "example"}),
`public-read`,
(rsErr, S3err, data)=>{
//other code...
});
License
MIT