fix
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user