This project is a backend service for image processing, similar to Cloudinary. It allows users to upload images, apply transformations, and retrieve images in different formats. The system includes user authentication, image management, and efficient retrieval mechanisms.
This project was implemented based on the roadmap from roadmap.sh.
- Sign-Up: Users can create an account.
- Log-In: Users can log in.
- JWT Authentication: Secure endpoints using JWTs for authenticated access.
- Upload Image: Users can upload images.
- Transform Image: Perform transformations such as resize, crop, rotate, watermark, etc.
- Retrieve Image: Fetch saved images in different formats.
- List Images: View all uploaded images with metadata.
- Resize
- Crop
- Rotate
- Watermark
- Flip
- Mirror
- Compress
- Change format (JPEG, PNG, etc.)
- Apply filters (grayscale, sepia, etc.)
- Language: Go
- Framework: Gin (HTTP server)
- Database: PostgreSQL with SQLC
- Storage: AWS S3
- Image Processing:
github.com/disintegration/imaging - Authentication: JWT (JSON Web Tokens)
- Deployment: Docker with
docker-compose
-
Clone the repository:
git clone https://github.com/your-repo/image-processing-service.git cd image-processing-service -
Install dependencies:
go mod tidy
-
Set up environment variables: Create a
.envfile at the root directory of the project, and add the following config settings.SERVER_PORT=:8080 JWT_SECRET=<your-secret-key> JWT_EXPIRATION_MINUTES=60 STORAGE_REGION=ap-northeast-2 STORAGE_KEY=<your-storage-key> STORAGE_SECRET=<your-storage-secret> BUCKET_NAME=image-processing-app-ngowi DATABASE_URL=postgres://admin:<your-db-password>@localhost:5030/main POSTGRES_DB=main POSTGRES_USER=admin POSTGRES_PASSWORD=<your-db-password>
-
Run database migrations:
make migrate-up
-
Start the service:
go run cmd/main.go
- Register:
POST /api/v1/auth/register - Login:
POST /api/v1/auth/login
- Upload Image:
POST /api/v1/images - Transform Image:
POST /api/v1/images/:id/transform - Retrieve Image:
GET /api/v1/images/:id - List Images:
GET /api/v1/images?page=1&limit=10
#!/bin/bash
# Register
curl -X POST http://localhost:8080/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "michael53161@gmail.com.com", "password": "coolhand"}'
# Login
curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "michael53161@gmail.com.com", "password": "coolhand"}'
ACCESS_TOKEN="your_jwt_token_here"
# Upload Image
curl -X POST http://localhost:8080/api/v1/images/ \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-F "image=@/Users/michael/Desktop/sky.jpg"
# Get Image
curl -X GET http://localhost:8080/api/v1/images/a80b97f6-c411-4093-adfa-e84682341e62 \
-H "Authorization: Bearer $ACCESS_TOKEN"
# Get All Images
curl -X GET http://localhost:8080/api/v1/images/ \
-H "Authorization: Bearer $ACCESS_TOKEN"
# Test Image Rotate
curl -X POST http://localhost:8080/api/v1/images/a80b97f6-c411-4093-adfa-e84682341e62/transform \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"transformations": {"rotate": 90}}'
# Test Grayscale
curl -X POST http://localhost:8080/api/v1/images/a80b97f6-c411-4093-adfa-e84682341e62/transform \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"transformations": {"filters": {"grayscale": true}}}'
# Test Sepia
curl -X POST http://localhost:8080/api/v1/images/a80b97f6-c411-4093-adfa-e84682341e62/transform \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"transformations": {"filters": {"sepia": true}}}'