fix: Proper file extensions inside Minios

This commit is contained in:
April Hall 2025-02-21 19:36:31 -05:00
parent 188d3e8318
commit 3d467e8219
Signed by: arithefirst
GPG Key ID: 4508A15C4DB91C5B
2 changed files with 14 additions and 3 deletions

View File

@ -23,7 +23,18 @@ class MinioClient {
});
}
async uploadProfile(stream: Readable) {
private getFileExtension(mimetype: string): string {
switch (mimetype) {
case 'image/jpeg':
return '.jpg';
case 'image/png':
return '.png';
default:
throw new Error('Unsupported file type');
}
}
async uploadProfile(stream: Readable, mime: string) {
try {
const bucket = 'profile-photos';
if (await !this.client.bucketExists(bucket)) {
@ -31,7 +42,7 @@ class MinioClient {
console.log('Bucket "' + bucket + '" created in "us-east-1".');
}
const objectId = v4();
const objectId = `${v4()}${this.getFileExtension(mime)}`;
const upload = await this.client.putObject(bucket, objectId, stream);
return {
bucket,

View File

@ -23,7 +23,7 @@ export const POST = async ({ request }) => {
const buffer = await file.arrayBuffer();
const stream = Readable.from(Buffer.from(buffer));
const uploadResponse = await fsClient?.uploadProfile(stream);
const uploadResponse = await fsClient?.uploadProfile(stream, file.type);
return json(uploadResponse);
} catch (e) {