fileUtils.ts 652 B

123456789101112131415161718192021222324252627
  1. /**
  2. * Manipulation des images
  3. */
  4. class FileUtils {
  5. /**
  6. * Returns a blob with the given data and the file's type
  7. *
  8. * @param data
  9. * @param filetype
  10. */
  11. public static newBlob(data: BlobPart, filetype: string = 'image/jpeg'): Blob {
  12. return new Blob([data], { type: filetype })
  13. }
  14. /**
  15. * Transforme un Blob en Base64
  16. * @param {Blob} blob
  17. */
  18. public static blobToBase64(blob: Blob): Promise<string> {
  19. return new Promise((resolve, _reject) => {
  20. const reader = new FileReader()
  21. reader.onloadend = () => resolve(reader.result as string)
  22. reader.readAsDataURL(blob)
  23. })
  24. }
  25. }
  26. export default FileUtils