Front: remove file64 dependency
This commit is contained in:
committed by
Clément Le Bihan
parent
e0f2674811
commit
8ab85ab689
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user