Skip to content

Commit 3ffe15d

Browse files
committed
fix(s3): add fallback for unrecognized MIME types in uploadSimple
getExtension() can return undefined for unrecognized MIME types. Added fallback chain: try URL extension, then default to 'bin'.
1 parent abbe492 commit 3ffe15d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

libraries/nestjs-libraries/src/upload/s3.storage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export class S3Storage implements IUploadProvider {
7373
const contentType =
7474
loadImage?.headers?.get('content-type') ||
7575
loadImage?.headers?.get('Content-Type');
76-
const extension = getExtension(contentType)!;
76+
// Fallback to 'bin' if MIME type is unrecognized, or try to extract from URL
77+
const extension = getExtension(contentType) || path.split('.').pop()?.split('?')[0] || 'bin';
7778
const id = makeId(10);
7879
const datePath = this.getDatePath();
7980
const key = `${datePath}/${id}.${extension}`;

0 commit comments

Comments
 (0)