From 32b2d251590a84c8c1476bfc2d0ddcfd0089f003 Mon Sep 17 00:00:00 2001 From: Mat Sz Date: Wed, 23 Aug 2023 18:22:32 +0200 Subject: [PATCH] ensure mime type of blob is preserved --- src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 59d152c..8e2f6e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,7 +29,7 @@ export const toFile = async ( const blob = await toBlob(file); return new File([blob], name || '', { - type, + type: type || blob.type, }); }; @@ -43,7 +43,10 @@ export const toBlob = async (file: FileType, type?: string): Promise => { return new Blob([file], { type: type || file.type, }); - } else if (typeof file === 'string' && file.startsWith('blob:')) { + } else if ( + typeof file === 'string' && + (file.startsWith('blob:') || validateDataURL(file)) + ) { const res = await fetch(file); return await res.blob(); }