This project is a file upload system that allows users to upload, update, download, and delete files. The system uses Multer for handling file uploads, MongoDB for storing file metadata, and AWS S3 for storing the actual files. It also includes endpoints for retrieving file information and downloading files securely using signed URLs.
- File Upload: Upload files to the server and store metadata in MongoDB.
- File Download: Securely download files using signed URLs from AWS S3.
- File Metadata: Retrieve and update file metadata stored in MongoDB.
- File Deletion: Delete files from AWS S3 and remove corresponding metadata from MongoDB.
- Authentication: Basic authentication system to manage user sessions and secure file operations.
- Express: Web framework for Node.js.
- Mongoose: MongoDB object modeling tool.
- Multer: Middleware for handling file uploads.
- AWS SDK v3: For interacting with AWS S3.
- dotenv: For loading environment variables.
- Node.js
- MongoDB
- AWS account
-
Clone the repository:
git clone https://github.com/Ahlamghribi/HelloWorld-Hornet.git cd HelloWorld-Hornet -
Install dependencies:
npm install
-
Create a
.envfile in the root directory and add the following variables:MONGO_URI=your_mongo_connection_string AWS_ACCESS_KEY_ID=your_aws_access_key_id AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key AWS_REGION=your_aws_region S3_BUCKET_NAME=your_s3_bucket_name PORT=5000
-
Start the server:
npm start
-
Upload a file:
- Endpoint:
POST /upload - Form Data:
file,description
- Endpoint:
-
Get file information:
- Endpoint:
GET /file/:id
- Endpoint:
-
Update file metadata:
- Endpoint:
PUT /file/:id - Body:
{ "description": "new description" }
- Endpoint:
-
Download a file:
- Endpoint:
GET /file/download/:id
- Endpoint:
-
Delete a file:
- Endpoint:
DELETE /file/:id
- Endpoint:
To upload a file using Postman:
- Select
POSTmethod and enterhttp://localhost:5000/upload. - In the
Bodytab, selectform-data. - Add a key named
file, set type toFile, and choose the file to upload. - Add another key named
description, set type toText, and enter a description for the file. - Send the request.