-
Notifications
You must be signed in to change notification settings - Fork 156
Description
Summary
Currently, users can only choose profile avatars from preset DiceBear options. This issue proposes adding support for uploading a custom profile image from the local device, stored and served by the backend.
Goal
Allow authenticated users to upload a JPG/PNG profile image, save it on the backend, and immediately display it in the UI with persistence across refreshes.
Backend Changes
** New Controller**
File: backend/controllers/upload_controller.go
Function: UploadAvatar(c *gin.Context)
Responsibilities:
- Accept multipart file upload
- Enforce max file size: 5MB
- Validate file types: .jpg, .jpeg, .png
- Save file to: ./uploads/avatars/
- Return public URL:
Server Setup
File: backend/cmd/server/main.go
Serve uploads directory statically:
router.Static("/uploads", "./uploads")
Register protected route:
auth.POST("/user/upload-avatar", controllers.UploadAvatar)
Frontend Changes
Profile Service
File: frontend/src/services/profileService.ts
- Add uploadAvatar(token, file) method
- Use FormData
- POST to /user/upload-avatar
- Return uploaded avatar URL
Profile Page UI
File: frontend/src/Pages/Profile.tsx
- Add hidden
- Add an Upload Avatar button (or camera icon)
- On file selection:
- Call uploadAvatar
- Update avatar URL in state
- Reflect change immediately in UI
Verification Plan
Backend
1. Test with Postman:
POST /user/upload-avatar
- Confirm file saved in backend/uploads/avatars/
- Confirm API returns valid public URL
Frontend
- Login → Profile page
- Click Upload Avatar
- Select JPG/PNG image
- Avatar updates instantly
- Refresh page → avatar persists
Labels (suggested)
feature
frontend
backend
enhancement