f195bba03d
- Updated SignIn and Profile components with new background styles and layout adjustments for a more modern look. - Refined button styles in GoogleSigninButton and SigninWithPassword for better user interaction feedback. - Enhanced InputGroup and Select components with improved styling and error handling for a more consistent user experience. - Adjusted Sidebar and Header components for better responsiveness and visual appeal. - Implemented spotlight effect in UserInfo dropdown for a more engaging user interface.
5.3 KiB
5.3 KiB
Frontend Guide: File Upload + Profile Image APIs
This is a simple reference for frontend integration with file upload, file retrieval, and setting profile image.
Base URLs
- Admin APIs:
/admin/v1 - Customer/Public APIs:
/api/v1
All protected endpoints require:
Authorization: Bearer <access_token>
1) Login (Admin)
Use this when you want to update admin user profile image.
Request
POST /admin/v1/profile/loginContent-Type: application/json
{
"username": "admin",
"password": "Admin1234"
}
Response (success)
{
"success": true,
"message": "Login successful",
"data": {
"user": {
"id": "65bc1234567890abcdef1234",
"profile_image": null
},
"access_token": "<jwt>",
"refresh_token": "<jwt>",
"expires_at": 1776783486
}
}
2) Upload File (GridFS)
Use multipart form upload.
Admin route
POST /admin/v1/files/upload
Customer route
POST /api/v1/files/upload
Form fields
file(required, File)category(optional, string), example:profile_imagestags(optional, repeatable), example:user,profiledescription(optional, string)
Response (success)
{
"file_id": "69e7899c2053abd3fa5433e0",
"filename": "avatar.png",
"content_type": "image/png",
"size": 123456,
"message": "File uploaded successfully"
}
3) Get File Info
GET /admin/v1/files/{file_id}/infoGET /api/v1/files/{file_id}/info
Response (success)
{
"file_id": "69e7899c2053abd3fa5433e0",
"filename": "avatar.png",
"content_type": "image/png",
"size": 123456,
"uploaded_by": "65bc1234567890abcdef1234",
"uploaded_at": "2026-04-21T14:28:44.787Z",
"category": "profile_images",
"tags": ["user", "profile"],
"description": "sample profile photo"
}
4) Download File
GET /admin/v1/files/{file_id}/downloadGET /api/v1/files/{file_id}/download
Returns file binary stream.
Useful for image URL:
http://localhost:8080/admin/v1/files/<file_id>/download- or
http://localhost:8080/api/v1/files/<file_id>/download
5) Set Admin User Profile Image
Upload does not update user profile automatically.
After upload, call profile update endpoint with the download URL.
Request
PUT /admin/v1/profileContent-Type: application/json
{
"profile_image": "http://localhost:8080/admin/v1/files/69e7899c2053abd3fa5433e0/download"
}
Response
- Success: standard success envelope with updated user data
- Failure example:
{
"success": false,
"message": "Bad Request",
"error": {
"code": "BAD_REQUEST",
"message": "failed to update user"
}
}
6) Verify Profile
GET /admin/v1/profile
Check:
data.profile_imageis now populated with file URL.
Common Errors
401 Unauthorized: missing/expired token413 Request Entity Too Large: file too big400 Unsupported file typeor validation error404 File not found: wrongfile_id
Suggested Frontend Flow (Admin)
- Login -> save
access_token - Upload image -> get
file_id - Build URL
.../admin/v1/files/{file_id}/download - Update profile with
profile_imageURL - Refresh profile screen via
GET /admin/v1/profile
Customer: Company Documents Upload
Customers can upload company documents using customer auth token.
Upload endpoint
POST /api/v1/files/upload
Recommended form-data for company docs
file: actual document filecategory:company_documentstags: repeatable. Suggested:companydocument<doc_type>(example:tax_certificate,registration,license)
description: human-readable note, example:Company tax certificate 2026
Example curl
CUSTOMER_TOKEN="<customer_access_token>"
curl -X POST "http://localhost:8080/api/v1/files/upload" \
-H "Authorization: Bearer ${CUSTOMER_TOKEN}" \
-F "file=@/absolute/path/to/company-doc.pdf" \
-F "category=company_documents" \
-F "tags=company" \
-F "tags=document" \
-F "tags=tax_certificate" \
-F "description=Company tax certificate 2026"
Response
{
"file_id": "69e8abcd2053abd3fa5433e1",
"filename": "company-doc.pdf",
"content_type": "application/pdf",
"size": 245632,
"message": "File uploaded successfully"
}
Fetch company docs list
Use list with category filter:
GET /api/v1/files?category=company_documents&limit=50&skip=0
You can also filter by tags:
GET /api/v1/files?category=company_documents&tags=tax_certificate
Download company doc
GET /api/v1/files/{file_id}/download
Important current behavior
- Upload works for customers and stores
uploaded_byascustomer_id. - Company now supports
document_file_idsfor mapping GridFS files.
Attach uploaded documents to company
Use admin company update endpoint after collecting uploaded file_id values:
PUT /admin/v1/companies/{company_id}
Request body includes regular company fields plus document_file_ids:
{
"name": "Opplens",
"type": "private",
"registration_number": "1234567890",
"tax_id": "1234567890",
"industry": "Technology",
"document_file_ids": [
"69e8abcd2053abd3fa5433e1",
"69e8abcd2053abd3fa5433e2"
]
}
document_file_ids is also returned in:
GET /admin/v1/companies/{id}GET /api/v1/companies(customer "my company" profile)