apache / cordova-plugin-file-transfer

Apache Cordova File Transfer Plugin
https://cordova.apache.org/
Apache License 2.0
595 stars 888 forks source link

No longer able to provide nested path #330

Open boedy opened 2 years ago

boedy commented 2 years ago

I believe https://github.com/apache/cordova-plugin-file-transfer/pull/310 broke the previous behaviour. It was possible to provide a nested path as target file. Now it will throw an error when doing so.

Code to reproduce

(() => {
  const fileTransfer = new FileTransfer();
  const url = 'http://cordova.apache.org/static/img/cordova_bot.png'
  const filePath = window.cordova.file.dataDirectory + 'nested/test.png';

  fileTransfer.download(
    url,
    filePath,
    file => console.log(file),
    error => console.error(error)
  );
})()

Possible fix

Adding this code snippet after line 727

if(file == null){
    file = new File(targetUri.getPath());
}
file.getParentFile().mkdirs();