feat: Implement S3 presigned URL fetching for user avatars and add an image proxy utility.
This commit is contained in:
@@ -53,3 +53,6 @@ export type {
|
||||
CreateFieldDto,
|
||||
UpdateFieldDto,
|
||||
} from './profile-fields.service';
|
||||
|
||||
// Upload Service
|
||||
export { uploadService } from './upload.service';
|
||||
|
||||
27
src/services/upload.service.ts
Normal file
27
src/services/upload.service.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import api from './api';
|
||||
|
||||
class UploadService {
|
||||
private basePath = '/upload';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URL is an S3 key (not a full URL or local path)
|
||||
*/
|
||||
isS3Key(url: string | null | undefined): boolean {
|
||||
if (!url) return false;
|
||||
// S3 keys don't start with http or /
|
||||
return !url.startsWith('http') && !url.startsWith('/');
|
||||
}
|
||||
}
|
||||
|
||||
export const uploadService = new UploadService();
|
||||
Reference in New Issue
Block a user