I am currently developing a mobile project using Cordova and Ionic2 using an external database resource that connects to the mobile via REST webServices.
The database has documents pdf saved that you have to send to the mobile and view the same. I am using the pdf in enconding Base64 through the webservices by Json.
I can get the string in base64, but I do not quite understand how to decode it and save it on mobile, which is Android to be able to see it.
Personally I couldn’t get base64 encoding and decoding of a PDF to work at all, because when decoding on the device part of the pdf file was just… gone (certain characters.) I ended up setting up a download link and using Transfer to download the file, and FileOpener to open it.
If you literally mean how to decode a base64 in javascript, it’s atob(), and btoa() to encode. If you want to try to get decoding and saving the file working, though I spent quite some time never succeeding at that, use File to save the decoded string on the device.
this code works fine in Android 6.0.1 (2016 - Marshmellow) Samsung mobiles, 5.1 (Lolipop) Micromax mobile but not in 5.1.1 Lolipop Samsung device & 7.0 Nougat Lenovo device. This is my problem. In not working
mobiles that PDF not created …
Here, The Android file directory opens using with this.file.externalDataDirectory it’s working fine, but the ios file open using what type of instance member I have to use.
I’m using the same code and getting the below error.
Kindly help me to resolve this.
*Refused to connect to ‘data:application/pdf;base64,SGVsbG8gV29ybGQ=’ because it violates the following Content Security Policy directive: "default-src ". Note that ‘connect-src’ was not explicitly set, so ‘default-src’ is used as a fallback.
Refused to connect to ‘data:application/pdf;base64,SGVsbG8gV29ybGQ=’ because it violates the document’s Content Security Policy.