This Node.js application provides a simple API endpoint for uploading files to Amazon S3 using the AWS SDK v3. It utilizes Express.js for handling HTTP requests, Multer for handling file uploads, and the aws-sdk library for interacting with Amazon S3.
Before getting started, ensure you have the following installed on your machine:
- Node.js
- npm (Node Package Manager)
-
Clone the repository:
git clone https://github.com/abdoil/s3-upload-API.git
-
Navigate to the project directory:
cd your-repo
-
Install dependencies:
npm install
-
Create a
.env
file in the project root and add your AWS credentials:AWS_ACCESS_KEY_ID=your-access-key AWS_SECRET_ACCESS_KEY=your-secret-key AWS_BUCKET_NAME=your-s3-bucket-name
-
Start the server:
node index.js
-
Make a POST request to
http://localhost:3000/upload
with one or more files attached.Example using curl:
curl -X POST -F "file=@/path/to/your/file.txt" http://localhost:3000/upload
-
The server will upload the file(s) to Amazon S3, and the response will be a JSON object containing the status and the modified keys:
{ "status": "success", "modifiedKeys": [ "https://your-s3-bucket-url/uploads/your-uuid-filename.txt" ] }
Adjust the AWS configuration and other settings in the .env
file.
Feel free to contribute by opening issues or creating pull requests.