cordova-plugin-file-transfer icon indicating copy to clipboard operation
cordova-plugin-file-transfer copied to clipboard

No longer able to provide nested path

Open boedy opened this issue 2 years ago • 0 comments

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();

boedy avatar Apr 20 '22 16:04 boedy