aws_upload_to_s3
v1.0.9
Published
This is use to upload files in AWS S3 bucket.
Downloads
13
Readme
File Upload to AWS S3
This is a Node.js utility for uploading files to Amazon S3.
Prerequisites
- Node.js (version v14.18.0 or higher)
- AWS account with S3 access
- Access key and secret key for your AWS account
Installation
Run npm i aws_upload_to_s3
Usage: 1.Import the setCredentials and uploadToS3 functions:
const {setCredentials, uploadToS3} = require("aws_upload_to_s3");
2.Set your AWS credetails and use uploadToS3 function for upload files:
Notes: The uploadToS3 function handles the file upload to AWS S3. Pass the request object (req) and response object (res) as parameters.
const MAX_FILE_SIZE = 5 * 1024 * 1024; //5MB (Please provide maxsize in Number not in string format).
app.post("/uploadFiles",async(req,res)=>{
try{
await setCredentials ("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY", "YOUR_BUCKET_NAME", MAX_FILE_SIZE);
const upload = await uploadToS3(req,res);
res.status(200).send(upload);
// handle success
}catch(error){
res.status(400).send(error);
// handle error
}
})
4.Start the server and handle the POST request to upload files.
5.In postman or UI in form-data Key name should be named as "file
" and you can able to upload upto 10 files.
Note: Key name should be named as "file
" another names won't support while uploading.
6.Make sure to replace the placeholder values (YOUR_ACCESS_KEY
, YOUR_SECRET_KEY
, YOUR_BUCKET_NAME
, MAX_FILE_SIZE
) with your actual AWS credentials and bucket information.