Reputation: 35
I'm trying to convert a base64 Image into a ".png" file. I am using the Ionic native file plugin to do this. First I am converting the base64 image into a Blob and then converting this Blob into a ".png" file.
When testing this in the web browser via "ionic serve" everything works perfectly but when testing this on an emulator or on a physical device it doesn't seem to work. The code runs without errors but when trying to log out the file type or file size I am getting 0 for the size and undefined for the type.
let base64 = this.formData.getParentSignature();
let signatureBlob = this.getBlob(base64);
let signatureFileName = firstName+"-"+lastName+"-Parent-"+"Signature.png";
var blob = new Blob([this.parentSignature], {type: 'image/png'});
var filePhoto = new File([signatureBlob], signatureFileName);
Upvotes: 0
Views: 291
Reputation: 35
So I figured this out myself and I'm posting it here in case anyone else runs into the same problem.
let base64 = this.formData.getParentSignature();
let signatureBlob = this.getBlob(base64);
let signatureFileName = firstName+"-"+lastName+"-Parent-"+"Signature.png";
var blob = new Blob([signatureBlob], {type: 'image/png'});
var filePhoto = new File([signatureBlob], signatureFileName);
Then I was able to rename the file:
let headers = new Headers();
headers.append('Content-Type','multipart/form-data');
let form = new FormData();
form.append('files', blob, signatureFileName);
Upvotes: 1