Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

ionic save base64 as file

let UUID = 'empleado-' + (new Date().getTime()).toString(16);

// imagen = data:image/jpeg;base64,/9j/4........
    let realData = imagen.split(",")[1];
    let blob = this.b64toBlob(realData, 'image/jpeg');

    this.file.checkDir(this.file.externalApplicationStorageDirectory, 'DirectorioFotos')
        .then(_ => {
          this.file.writeFile(this.file.externalApplicationStorageDirectory + 'DirectorioFotos/', UUID + '.jpg', blob).then(response => {
            // ACTION
          }).catch(err => {
            // ACTION
          })
        })
        .catch(err => {
          this.file.createDir(this.file.externalApplicationStorageDirectory, 'DirectorioFotos', false).then(result => {
            this.file.writeFile(this.file.externalApplicationStorageDirectory + 'DirectorioFotos/', UUID + '.jpg', blob).then(response => {
              // ACTION
            }).catch(err => {
              // ACTION
            })
          })
        });
 
 //convert base64 to blob
 b64toBlob(b64Data, contentType) {
    contentType = contentType || '';
    var sliceSize = 512;
    var byteCharacters = atob(b64Data);
    var byteArrays = [];

    for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
      var slice = byteCharacters.slice(offset, offset + sliceSize);

      var byteNumbers = new Array(slice.length);
      for (var i = 0; i < slice.length; i++) {
        byteNumbers[i] = slice.charCodeAt(i);
      }

      var byteArray = new Uint8Array(byteNumbers);

      byteArrays.push(byteArray);
    }

    var blob = new Blob(byteArrays, {type: contentType});
    return blob;
  }
Comment

PREVIOUS NEXT
Code Example
Typescript :: angular convert file to base64 
Typescript :: react typescript display firebase timestamp as date 
Typescript :: denoot 
Typescript :: set stroke style html canvas 
Typescript :: how to clear all products woocommerce keep category 
Typescript :: set localStorage angualr 
Typescript :: ratio of subplots matplotlib 
Typescript :: squash commits in remote branch 
Typescript :: remove all children of node in typescript 
Typescript :: typescript input 
Typescript :: No type arguments expected for interface ListAdapter 
Typescript :: get all the ids in an array of objects ts 
Typescript :: ionic modal controller pass parameter 
Typescript :: how to make comments in .env files 
Typescript :: subtracting two date objects in javacript 
Typescript :: how to send data between components in react using link 
Typescript :: mongoose to object keep all fields 
Typescript :: typescript algorithm to find repeating number sequences over time 
Typescript :: formgroup reset values 
Typescript :: typescript array with allowed object keys 
Typescript :: How to do Email validation using Regular expression in Typescript 
Typescript :: There can only be one default row without a when predicate function. 
Typescript :: @react-navigation/native route typescript 
Typescript :: how to use get element by id in angular 
Typescript :: how to push an object into an array typescript 
Typescript :: eslint airbnb react typescript 
Typescript :: what are data points 
Typescript :: dynamic subplots matplotlib 
Typescript :: react setstate in hooks to array of objects value 
Typescript :: mark occurances of elements in array cpp 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =