| 12345678910111213141516171819202122232425262728293031323334 |
- /**
- * Manipulation des images
- */
- class FileUtils {
- /**
- * Returns a blob with the given data and the image filetype
- *
- * @param data
- * @param filetype
- */
- public static newBlob(data: string, filetype: string = 'image/jpeg'): Blob {
- return new Blob([data as BlobPart], {type: filetype});
- }
- /**
- * Transforme un Blob en Base64
- * @param {Blob} blob
- */
- public static async blobToBase64(blob: Blob): Promise<string> {
- return new Promise((resolve, _) => {
- const reader = new FileReader();
- // @ts-ignore
- reader.onloadend = () => {
- // @ts-ignore
- let base64Data: string = reader.result;
- base64Data = base64Data.substring(base64Data.indexOf(',') + 1);
- resolve(base64Data);
- };
- reader.readAsDataURL(blob);
- });
- }
- }
- export default FileUtils
|