1.0.9 • Published 2 years ago

aws_upload_to_s3 v1.0.9

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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.

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago