cordova-plugin-file-transfer
cordova-plugin-file-transfer copied to clipboard
No longer able to provide nested path
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();