Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229646

Download / create file from byte array

$
0
0

@joconolimits
I basically want to convert Image URI to .pdf file.

So first I am converting an Image URI to Character Array and then I am converting it into binary.

After that I am using Write File API to create .pdf file.

After doing this code. I am facing an issue that when WriteFile gives me success and I open .pdf file through fileOpener or manually then it gives me error that Invalid Format.

This error only comes when I generate .pdf file.

Do you know how to solve it.

 this.screenshot.URI(80).then(succ=>{
        var byteCharacters = decodeURI(succ.URI)
         var byteNumbers = new Array(byteCharacters.length);
          for (var i = 0; i < byteCharacters.length; i++) {
              byteNumbers[i] = byteCharacters.charCodeAt(i);
          }
          var byteArray = new Uint8Array(byteNumbers);
          var BINARY_ARR = byteArray.buffer;


         console.log("BINARY_ARR : ",BINARY_ARR )
          this.createFile(BINARY_ARR);
        }
      ,() => {
            this.showToast("There is an error!");
          })

  this.file.writeFile(cordova.file.externalDataDirectory,this.createFileName(),blob,true).then(succ=>{
      console.log("File write success : ", succ)
      this.fileOpener.open(
      succ.nativeURL,
      'application/pdf'
    ).then((success) => {
      console.log('success open file: ', success);
    }, (err) => {
      console.log('error open file', err);
    });

    },
    err=>{
      console.log(" write File error : ", err)
    })

Viewing all articles
Browse latest Browse all 229646

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>