This project is an image processing api that allows users to upload CSV files containing image URLs, processes the images, and provides status updates on the processing.
-
Clone the repository:
git clone https://github.com/Aicirou/image-processing-api.git cd image-processing-api
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory and add the following environment variables:PG_USER=postgres PG_HOST=localhost PG_PASSWORD=pASSword PG_DATABASE=myimagedb PG_PORT=5432 PORT=3000 WEBHOOK_URL=http://example.com/webhook
-
Ensure your PostgreSQL database is running and accessible.
-
Start the server:
npm start
-
For development with hot-reloading:
npm run dev
-
Upload a sample CSV file for testing:
You can use the provided
dump.csv
file located in the root directory for testing purposes. This file contains sample image URLs to help you verify the functionality of the image processing system.smaple csv file:
S. No.,Product Name,Input Image Urls 1,SKU1,"https://picsum.photos/id/10/2500/1667, https://picsum.photos/id/11/2500/1667, https://picsum.photos/id/12/2500/1667" 2,SKU2,"https://picsum.photos/id/13/2500/1667, https://picsum.photos/id/14/2500/1667, https://picsum.photos/id/15/2500/1667" 3,SKU3,"https://picsum.photos/id/16/2500/1667, https://picsum.photos/id/17/2500/1667, https://picsum.photos/id/18/2500/1667" 4,SKU4,"https://picsum.photos/id/19/2500/1667, https://picsum.photos/id/20/2500/1667, https://picsum.photos/id/21/2500/1667" 5,SKU5,"https://picsum.photos/id/22/2500/1667, https://picsum.photos/id/23/2500/1667, https://picsum.photos/id/24/2500/1667"
- URL:
/api/upload
- Method:
POST
- Description: Upload a CSV file containing image URLs for processing.
- Request:
Content-Type
:multipart/form-data
file
: The CSV file to upload.
- Response:
202 Accepted
:{ "requestId": "unique-request-id" }
400 Bad Request
:{ "error": "Invalid file format" }
- URL:
/api/status/:requestId
- Method:
GET
- Description: Get the status of a specific request.
- Response:
200 OK
:{ "status": "processing/completed/failed", "output Images": [...] }
404 Not Found
:{ "error": "Request not found" }
src/index.js
: Entry point of the application. Sets up the Express server and connects to the database.src/routes/index.js
: Main router file that mounts all API routes.src/services/csvProcessor.js
: Service for processing CSV files.src/services/imageProcessor.js
: Service for processing images.src/tables/Request.js
: Defines theRequest
table schema and creation logic.
- Node.js: JavaScript runtime environment.
- Express.js: Web application framework for Node.js.
- PostgreSQL: Open-source relational database management system.
- Sharp: Image processing library for Node.js.
- Multer: Middleware for handling
multipart/form-data
requests. - dotenv: Loads environment variables from a
.env
file.