Skip to content

Commit

Permalink
ensure mime type of blob is preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-sz committed Aug 23, 2023
1 parent 0fc1978 commit 32b2d25
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const toFile = async (

const blob = await toBlob(file);
return new File([blob], name || '', {
type,
type: type || blob.type,
});
};

Expand All @@ -43,7 +43,10 @@ export const toBlob = async (file: FileType, type?: string): Promise<Blob> => {
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();
}
Expand Down

0 comments on commit 32b2d25

Please sign in to comment.