This commit is contained in:
pradeepkumar
2026-01-24 22:19:30 +05:30
parent 7d6ef356e2
commit a0559a17f1
6 changed files with 454 additions and 40 deletions

View File

@@ -146,6 +146,37 @@ class UploadService {
const encodedKey = encodeURIComponent(fileKey);
await api.delete(`${this.basePath}/${encodedKey}`);
}
/**
* Upload avatar image (uses agent profile ID as filename for auto-replacement)
*/
async uploadAvatar(
file: File,
onProgress?: (progress: UploadProgress) => void
): Promise<UploadedFile> {
// Step 1: Get presigned URL from backend (uses agent ID as filename)
const response = await api.post<{ data: PresignedUrlResponse }>(
`${this.basePath}/avatar-presigned-url`,
{
filename: file.name,
contentType: file.type,
}
);
const { uploadUrl, publicUrl, key } = response.data.data;
// Step 2: Upload directly to S3
await this.uploadToS3(uploadUrl, file, onProgress);
// Step 3: Return uploaded file info
return {
id: key,
name: file.name,
size: file.size,
type: file.type,
url: publicUrl,
uploadedAt: new Date().toISOString(),
};
}
}
export const uploadService = new UploadService();