Reputation: 1
In my apps running phonegap cordova 3.5 on android 4.4, using the file-transfer plugin to upload files works well but dowloading create an exception. I tested on the device and on the emulator blueStacks this code works fine with cordova 2.9 but when I update the cordova to 3.5 dowloading create an exception
the download function:
download = function () {
viewModel.popup_download.visible(false);
loadPanelVisible(true);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(viewModel.file_download_name(), {create: true, exclusive: false}, function() {
var ft = new FileTransfer();
uri="https://api.exemple-exemple.com/api/Dav/Download/"+path+"/"+viewModel.folder_downlod();
filePath=currPath+"/"+viewModel.file_download_name();
ft.download(uri,filePath,win_download,fail_download,false, {
headers: {
"HeaderUserData": JSON.stringify({ ID: id, Token: token }),
"HeaderDavData": JSON.stringify({ UserName: viewModel.userId_dav(), Password: viewModel.userPassword_dav() }),
}
});
}, fail);
}, fail);
}
Upvotes: 0
Views: 2431
Reputation: 396
you got problem in spaces and special chars, you must use encodeURI before you send the request.
download = function () {
viewModel.popup_download.visible(false);
loadPanelVisible(true);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(viewModel.file_download_name(), {create: true, exclusive: false}, function() {
var ft = new FileTransfer();
uri="https://api.phosphorus-technologies.com/api/Dav/Download/"+path+"/"+viewModel.folder_downlod();
filePath=currPath+"/"+viewModel.file_download_name();
uri = encodeURI(uri);
ft.download(uri,filePath,win_download,fail_download,false, {
headers: {
"HeaderUserData": JSON.stringify({ ID: id, Token: token }),
"HeaderDavData": JSON.stringify({ UserName: viewModel.userId_dav(), Password: viewModel.userPassword_dav() }),
}
});
}, fail);
}, fail);}
Upvotes: 3
Reputation: 2427
The variable currPath is never defined, and I don't think you want to use it at all. You passed your download folder from the viewModel, so then get the folder result in the callback.
download = function () {
viewModel.popup_download.visible(false);
loadPanelVisible(true);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(viewModel.folder_downlod(), {create: true, exclusive: false}, function(filePath) { // ADD PARAMETER HERE
var ft = new FileTransfer();
uri="https://api.phosphorus-technologies.com/api/Dav/Download/"+path+"/"+viewModel.folder_downlod(); //IS THIS A VALID URL ENDING IN THE FOLDER NAME?
//REMOVE FILE PATH HERE
ft.download(uri,filePath,win_download,fail_download,false, {
headers: {
"HeaderUserData": JSON.stringify({ ID: id, Token: token }),
"HeaderDavData": JSON.stringify({ UserName: viewModel.userId_dav(), Password: viewModel.userPassword_dav() }),
}
});
}, fail);
}, fail);
}
It worries me that you construct your API call ending with a folder, because this code will only work to download a single file. I think it may just be that the naming is inconsistent.
Upvotes: 0