ionic-native/file + ionic-native/http download not working

560 views Asked by At

Using code from this answer https://stackoverflow.com/a/63585081/7751910 and can't get it to work. Don't have physical ios device, so using Xcode simulator. This is my code with console.log()'s:

public downloadFileAndStore(fileUrl: string): void {

let filePath: string;

if (this.platform.is('ios')) {
  filePath = this.file.documentsDirectory + this.getFileName(fileUrl);
} else {  // for iOS use this.file.documentsDirectory
  filePath = this.file.dataDirectory + this.getFileName(fileUrl);
}

this.nativeHTTP.downloadFile(fileUrl, {}, {}, filePath).then((response: any) => {
   // prints 200
   console.log('download success', response);
   for (const key in response) {
     if (Object.prototype.hasOwnProperty.call(response, key)) {
       const element = response[key];
       console.log(key);
       console.log(element);
     }
   }
}).catch((err: any) => {
    // prints 403
    console.log('download error', err.status);
    // prints Permission denied
    console.log('download error', err.error);
});

}

And here is the output I'm getting in Xcode console when I try to call the method: enter image description here

But nevertheless nothing is downloaded.

Upd: on real device doesn't work either

0

There are 0 answers