0
votes

i want to download a file into my ionic-2-app. i use ionic native Transfer plugin with the following script:

let headers = new Headers();
    headers.append('TOKEN-NAME', storedtoken);

    let url = storedendpoint.apiendpoint + 'path/to/api/force/download/file';

    File.resolveLocalFilesystemUrl(cordova.file.applicationStorageDirectory).then((dirEntry) => {

    console.log('resolveLocalFilesystemUrl: ', dirEntry);

    this.transfer.download(encodeURI(url), dirEntry.nativeURL + filename, true, {headers: headers})
           .then((entry) => {
              console.log('Transfer: ', entry);
           }, (error) => {
              console.log('Transfer Error: ', error);
           })

     });

But i get the following error:

body: "Could not create target file"

code: 1

exception: null

http_status: 200

source: "http://domain/apiendpoint/api/path/to/api/force/download/file"

target: "file:////var/mobile/Containers/Data/Application/XXXXX-YYYYY-WWWW-1234-DSFR45RFDT65T/filename.doc"

The Download works perfectly if i try it in Browser.

1

1 Answers

0
votes

ok, found the problem:

cordova.file.applicationStorageDirectory

is read only. it works with

 cordova.file.cacheDirectory