Front: remove file64 dependency

This commit is contained in:
Arthur Jamet
2023-09-07 16:45:36 +02:00
committed by Clément Le Bihan
parent e0f2674811
commit 8ab85ab689
4 changed files with 24 additions and 7 deletions
+23
View File
@@ -0,0 +1,23 @@
// SRC: https://github.com/encrypit/file64/blob/master/src/base64-to-blob.ts
export async function base64ToBlob(base64: string): Promise<Blob> {
const response = await fetch(base64);
let blob = await response.blob();
const mimeType = getMimeType(base64);
if (mimeType) {
// https://stackoverflow.com/a/50875615
blob = blob.slice(0, blob.size, mimeType);
}
return blob;
}
const mimeRegex = /^data:(.+);base64,/;
/**
* Gets MIME type from Base64.
*
* @param base64 - Base64.
* @returns - MIME type.
*/
function getMimeType(base64: string) {
return base64.match(mimeRegex)?.slice(1, 2).pop();
}