|
| 1 | +# Welcome to the File Uploader Server! |
| 2 | + |
| 3 | +This project is a simple Node.js server built with `express`, `multer`, and `cors` to handle file uploads and serve static files. |
| 4 | + |
| 5 | +## 📖 Features |
| 6 | + |
| 7 | +- Handles file uploads with unique filenames to avoid overwriting. |
| 8 | +- Serves uploaded files for download via a static endpoint. |
| 9 | +- Uses `cors` to allow cross-origin requests. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +1. Navigate to the project directory: |
| 14 | + ```file-upload-server``` |
| 15 | +2. Install dependencies: |
| 16 | + ```npm install``` |
| 17 | + |
| 18 | +## Development |
| 19 | + |
| 20 | +Run the server: |
| 21 | + |
| 22 | +``` |
| 23 | +npm run start |
| 24 | +``` |
| 25 | + |
| 26 | +By default, the server runs on http://localhost:3001. You can upload files via the `/upload` endpoint and access uploaded files via |
| 27 | +the `/uploads` endpoint. |
| 28 | + |
| 29 | +## Endpoints |
| 30 | + |
| 31 | +### Upload Files |
| 32 | + |
| 33 | +**POST** `/upload` |
| 34 | + |
| 35 | +- Accepts a single file in the `file` field of the request. |
| 36 | +- Returns the uploaded file's public path on success. |
| 37 | + |
| 38 | +Example Response: |
| 39 | + |
| 40 | +```json |
| 41 | +{ |
| 42 | + "success": true, |
| 43 | + "message": "File uploaded successfully", |
| 44 | + "filePath": "/uploads/<filename>" |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +### Access Uploaded Files |
| 49 | + |
| 50 | +**GET** `/uploads/<filename>` |
| 51 | + |
| 52 | +- Serves static files from the `uploads` directory. |
| 53 | + |
| 54 | +You can now use the server to handle file uploads and serve them to clients. |
| 55 | + |
| 56 | +### 📦 Use Example |
| 57 | + |
| 58 | +You can integrate the uploader server using the **Uploader** component. |
| 59 | +For detailed documentation, refer to |
| 60 | +the [Uploader Documentation](https://formengine.io/documentation/components-library/fields-components/uploader). |
| 61 | + |
| 62 | +1. **Set the Action URL:** |
| 63 | + In the component's `Action URL` property, provide the URL to your server's upload endpoint. |
| 64 | + Example: http://localhost:3001/upload |
| 65 | + |
| 66 | +2. **Upload Workflow:** |
| 67 | + The component will send the file to the server via the specified `Action URL`. |
| 68 | + |
| 69 | + |
0 commit comments