feat: Implement S3 presigned URL fetching for user avatars and add an image proxy utility.

This commit is contained in:
pradeepkumar
2026-01-26 22:43:41 +05:30
parent b927d89e49
commit ba29257ba5
4 changed files with 105 additions and 4 deletions

View File

@@ -53,3 +53,6 @@ export type {
CreateFieldDto,
UpdateFieldDto,
} from './profile-fields.service';
// Upload Service
export { uploadService } from './upload.service';

View 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();