No errors while running, but when viewing the resulting base64 in page the image is corrupt. The base64 string when reading the image after saving it is a lot longer than the one im asking it to save.
Related code:
this.pictureDir=this.file.dataDirectory+'pictures/';
public saveImage(base64:string, name:string):Promise<string>{
return new Promise((resolve, reject)=>{
this.file.writeFile(this.pictureDir, name, base64, )
.then((data)=>{
resolve(this.pictureDir+name);
})
.catch((err)=>{
console.log(err.message)
reject(err);
})
})
}
public imgUriToBase64(imgUri:string):Promise<string>{
return new Promise((resolve, reject)=>{
let path:[string,string]=CatchService.splitUri(imgUri);
this.file.readAsDataURL(path[0],path[1])
.then((data)=>{
resolve(data);
})
.catch((err)=>{
console.log(err.message);
reject(err);
})
})
}
public static splitUri(imgUri:string):[string,string]{
let path:string[]=new Array<string>();
let file:string[]=new Array<string>();
let fileFound:boolean=false;
for(let i:number=imgUri.length-1;i>=0;i--){
if(imgUri.charAt(i)=='/'){
fileFound=true;
}
if(!fileFound){
file.push(imgUri.charAt(i));
}else{
path.push(imgUri.charAt(i));
}
}
let returnPath:string='';
let returnFile:string='';
for(let c of path){
returnPath=c+returnPath;
}
for(let c of file){
returnFile=c+returnFile;
}
return [returnPath, returnFile];
}
Thanks for the help.
Sorry if wrong format etc, new to the forum