s3 fix
This commit is contained in:
@@ -101,6 +101,13 @@ class AgentsService {
|
||||
);
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
async getFieldValuesByAgentId(id: string): Promise<GetFieldValuesResponse> {
|
||||
const response = await api.get<ApiResponse<GetFieldValuesResponse>>(
|
||||
`${this.basePath}/${id}/field-values`
|
||||
);
|
||||
return response.data.data;
|
||||
}
|
||||
}
|
||||
|
||||
export const agentsService = new AgentsService();
|
||||
|
||||
@@ -149,6 +149,7 @@ class UploadService {
|
||||
|
||||
/**
|
||||
* Upload avatar image (uses agent profile ID as filename for auto-replacement)
|
||||
* Returns the S3 key (not full URL) for storage in database
|
||||
*/
|
||||
async uploadAvatar(
|
||||
file: File,
|
||||
@@ -162,21 +163,32 @@ class UploadService {
|
||||
contentType: file.type,
|
||||
}
|
||||
);
|
||||
const { uploadUrl, publicUrl, key } = response.data.data;
|
||||
const { uploadUrl, key } = response.data.data;
|
||||
|
||||
// Step 2: Upload directly to S3
|
||||
await this.uploadToS3(uploadUrl, file, onProgress);
|
||||
|
||||
// Step 3: Return uploaded file info
|
||||
// Step 3: Return uploaded file info with KEY (not full URL) for database storage
|
||||
return {
|
||||
id: key,
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
type: file.type,
|
||||
url: publicUrl,
|
||||
url: key, // Store the S3 key, not the full URL
|
||||
uploadedAt: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a presigned download URL for an S3 key
|
||||
*/
|
||||
async getPresignedDownloadUrl(key: string): Promise<string> {
|
||||
const response = await api.get<{ data: { url: string } }>(
|
||||
`${this.basePath}/presigned-download-url`,
|
||||
{ params: { key } }
|
||||
);
|
||||
return response.data.data.url;
|
||||
}
|
||||
}
|
||||
|
||||
export const uploadService = new UploadService();
|
||||
|
||||
Reference in New Issue
Block a user