File Download

The File download is not working if the file name contain " : " only for dis special character .
Here is my code

var uri = “http://192.168.0.15/action_item/attachment/” + attach.attach_id +’/’;
/*mobile not allow to download if filename have “:” symbole */
//var pos = attach.attach_user_filename.lastIndexOf( attach.attach_user_filename.charAt( attach.attach_user_filename.indexOf(":")+1) );
var downloadUrl = “///storage/emulated/0/Download/” + attach.attach_user_filename;
var fileTransfer = new FileTransfer();
var token = (localStorage.getItem(‘wizApp.refresh_token’) ? localStorage.getItem(‘wizApp.refresh_token’) : localStorage.getItem(‘wizApp.token’));
fileTransfer.download( uri, downloadUrl,
function(entry) {
alert(“File Downloaded successfully”);
},
function(error) {
alert(JSON.stringify(error));
console.log(JSON.stringify(error));
},
false,
{
headers: {
“Authorization”: 'JWT ’ + token
}
}
);

This issue happens on older android versions
Try escaping the URI

encodeURIComponent(url)

var uri = encodeURIComponent(“http://192.168.0.15/action_item/attachment/” + attach.attach_id +’/’);
var downloadUrl = “///storage/emulated/0/Download/” + attach.attach_user_filename;
var fileTransfer = new FileTransfer();
var token = (localStorage.getItem(‘wizApp.refresh_token’) ? localStorage.getItem(‘wizApp.refresh_token’) : localStorage.getItem(‘wizApp.token’));
fileTransfer.download( uri, downloadUrl,
function(entry) {
alert(“File Downloaded successfully”);
alert(JSON.stringify(entry));
console.log(JSON.stringify(entry))
},
function(error) {
alert(JSON.stringify(error));
console.log(JSON.stringify(error))

                    },
                    false,
                    {
                        headers: {
                            "Authorization": 'JWT ' + token
                        }
                    }
                );

Here is my code added “encodeURIComponent” url still is failing with all files … its happening for all the version .

Sorry .
Its working …

Here is my code

var uri = encodeURI(“http://192.168.0.15/action_item/attachment/” + attach.attach_id +’/’);
var downloadUrl = “///storage/emulated/0/Download/” + encodeURIComponent(attach.attach_user_filename);
var fileTransfer = new FileTransfer();
var token = (localStorage.getItem(‘wizApp.refresh_token’) ? localStorage.getItem(‘wizApp.refresh_token’) : localStorage.getItem(‘wizApp.token’));
fileTransfer.download( uri, downloadUrl,
function(entry) {
alert(“File Downloaded successfully”);
alert(JSON.stringify(entry));
console.log(JSON.stringify(entry))
},
function(error) {
alert(JSON.stringify(error));
},
false,
{
headers: {
“Authorization”: 'JWT ’ + token
}
}
);

1 Like