Releases: Prokken/file-upload-with-mongodb
GridFS File Upload System with MongoDB
MongoDB File Upload API Documentation
This API allows users to upload, download, rename, and delete files in MongoDB using GridFS. It supports single and multiple file uploads, as well as various download formats, including zipped files and base64 encoding.
Base URL
<your_base_url>
Endpoints
1. Upload a File
Uploads a single file to MongoDB using GridFS.
- URL:
/upload/file
- Method:
POST
- Headers:
Content-Type: multipart/form-data
- Body:
file
: A file input with the file to be uploaded.
- Example Request:
- Body:
form-data Key: file Value: <file_path>/whatsapp-cloud-api.png
- Body:
- Success Response:
- Status:
200 OK
- Body:
{ "message": "File uploaded successfully", "fileId": "66e5f0563d20ffd1705bb1eb" }
- Status:
- Error Response:
- Status:
400 Bad Request
- Body:
{ "error": "Invalid file format or missing file" }
- Status:
2. Upload Multiple Files
Uploads multiple files to MongoDB using GridFS.
- URL:
/upload/files
- Method:
POST
- Headers:
Content-Type: multipart/form-data
- Body:
files
: Multiple files input.
- Example Request:
- Body:
form-data Key: files Value: <file_path>/graphics-designer.png, <file_path>/whatsapp-cloud-api.png
- Body:
- Success Response:
- Status:
200 OK
- Body:
{ "message": "Files uploaded successfully", "fileIds": ["66e5f0563d20ffd1705bb1eb", "66e5f0563d20ffd1705bb1ec"] }
- Status:
- Error Response:
- Status:
400 Bad Request
- Body:
{ "error": "Invalid files format or missing files" }
- Status:
3. Download a File
Downloads a single file from MongoDB using its file ID.
- URL:
/download/files/:fileId
- Method:
GET
- Path Variables:
fileId
: The ID of the file in MongoDB.
- Example Request:
- URL:
/download/files/66e5f0563d20ffd1705bb1eb
- URL:
- Success Response:
- Status:
200 OK
- Headers:
Content-Disposition: attachment; filename=<filename>
- Body: File content.
- Status:
- Error Response:
- Status:
404 Not Found
- Body:
{ "error": "File not found" }
- Status:
4. Download Multiple Files as Zip
Downloads multiple files from MongoDB in a zipped format.
- URL:
/download/files-zip
- Method:
GET
- Success Response:
- Status:
200 OK
- Headers:
Content-Disposition: attachment; filename=files.zip
- Body: Zipped file content.
- Status:
- Error Response:
- Status:
404 Not Found
- Body:
{ "error": "Files not found or unable to zip" }
- Status:
5. Download Multiple Files as Base64
Downloads multiple files from MongoDB encoded in base64.
- URL:
/download/files-base64
- Method:
GET
- Success Response:
- Status:
200 OK
- Body:
{ "files": [ { "filename": "file1.png", "content": "<base64_encoded_content>" }, { "filename": "file2.png", "content": "<base64_encoded_content>" } ] }
- Status:
- Error Response:
- Status:
404 Not Found
- Body:
{ "error": "Files not found" }
- Status:
6. Rename a File
Renames an existing file in MongoDB.
- URL:
/rename/file/:fileId
- Method:
PUT
- Path Variables:
fileId
: The ID of the file in MongoDB.
- Body:
- Content-Type:
application/json
- JSON:
{ "filename": "new-filename.png" }
- Content-Type:
- Success Response:
- Status:
200 OK
- Body:
{ "message": "File renamed successfully" }
- Status:
- Error Response:
- Status:
404 Not Found
- Body:
{ "error": "File not found" }
- Status:
7. Delete a File
Deletes a file from MongoDB using its file ID.
- URL:
/delete/file/:fileId
- Method:
DELETE
- Path Variables:
fileId
: The ID of the file in MongoDB.
- Example Request:
- URL:
/delete/file/66e5efa3c337b9d59aa5b858
- URL:
- Success Response:
- Status:
200 OK
- Body:
{ "message": "File deleted successfully" }
- Status:
- Error Response:
- Status:
404 Not Found
- Body:
{ "error": "File not found" }
- Status:
Ensure to replace
<your_base_url>
with the actual base URLhttp://localhost:3000
ornumber you've ported
of your API service. This documentation should provide clear guidance on how to interact with the file upload system using the endpoints provided.