I have an ionic 2 app where I am downloading blob pdf and would like to save it to local storage. I’ve tried using the Corodova File to write to the directory however I am getting a typerror:
“Uncaught (in promise): Type Error TypeError at Object.checkArgs… module.exports.resolveLocalFileSystemURL)”
Here is the code I am running at the moment, appreciate any help on this on how I could get it working???
let headers: any;
let params = {format: format};
headers = this.authService.getHeaders();
return this.http.get('URL_ADDRESS_GOES_HERE' , {responseType: ResponseContentType.Blob, headers: headers, params: params})
.subscribe(
(res: any) => {
let obj: any;
let fileName: string;
if (this.format === "PDF") {
obj = new Blob([res.blob()], { type: 'application/pdf' })
fileName = name + ".pdf";
}
if (this.platform.is('cordova')) {
// Mobile (Not working)
this.file.writeFile(this.file.dataDirectory, fileName, obj);
} else {
// Web-browser (Working)
FileSaver.saveAs(obj, fileName);
}
})