This repository contains a simple Node.js application that allows file uploads through an API using Express.js and Multer. The uploaded files are stored locally in a designated directory, and the API can handle multiple file uploads at once.
- Multiple File Uploads: Supports uploading multiple files in a single request.
- Express.js: Backend server framework to handle HTTP requests.
- Multer: Middleware for handling file uploads and storing them on the server.
- Node.js (v12.x or higher)
- NPM (v6.x or higher)
git clone https://github.com/yourusername/file-upload-api.git
cd file-upload-apinpm install
npm install express
npm install multernode server.jsThis will start the server on port 3000.
POST /upload
- This endpoint allows you to upload one or multiple files.
- Use form-data with the key
filesfor file uploads.
curl -X POST http://localhost:3000/upload -F 'files=@/path/to/file1' -F 'files=@/path/to/file2'{
"message": "Files uploaded successfully."
}All uploaded files will be stored in the uploads/ directory located in the project root.
- Upload Directory: You can change the directory where the files are uploaded by modifying the
uploadPathvariable inapp.js. - File Naming: The default behavior stores files with their original name. You can customize the file naming strategy inside the
filenamefunction in the Multer configuration.
This project is licensed under the MIT License. Feel free to use, modify, and distribute it as you see fit.
Feel free to fork the repository, make improvements, and submit a pull request. Any contributions to enhance the project are welcome!