Page 2 of 5

How to download a file using javascript

Posted: Tue Aug 13, 2013 12:58 pm
by Maryna Brodina

Hello! You need to define filePath. For example after codevar fileTransfer = new FileTransfer();/code add codevar filePath = "file://sdcard/XXXXX.pdf&quot/code where file:/// - path you use to save
XXXXX.pdf - name you use to save
Please note it wont't work in browser as it's PhoneGap feature, you would need to export and install app on device first.


How to download a file using javascript

Posted: Tue Aug 13, 2013 1:44 pm
by Nayef

1- Can i use appery.io Tester to test the app on device ?

2- Doesn't work see the code :

var fileTransfer = new FileTransfer();
var filePath = "file://sdcard/quickstart.pdf";
var uri = encodeURI("http://www.example.com/uploads/quicks...");

fileTransfer.download(
uri,
filePath,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false,
{
headers: {
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);


How to download a file using javascript

Posted: Tue Aug 13, 2013 1:50 pm
by Maryna Brodina

Yes, but some PhoneGap features might not work in Tester. If it doesn't work it tester then please try to install app on device. Please let us know about result.


How to download a file using javascript

Posted: Tue Aug 13, 2013 2:11 pm
by Nayef

Not working after install it


How to download a file using javascript

Posted: Tue Aug 13, 2013 6:01 pm
by Kateryna Grynko

Hi,

What are the errors in your app as a result?
Are you sure in header basic auth: "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==" ?


How to download a file using javascript

Posted: Tue Aug 13, 2013 6:27 pm
by Nayef

Hi,

1st : The result is nothing
2nd : I don't know what is Authorization and how i use it in this case .


How to download a file using javascript

Posted: Tue Aug 13, 2013 7:01 pm
by Kateryna Grynko

Please replace codeconsole.log/codewithcodealert/codeand show us the result.

Also please find out if http-authorization is needed on site where you download file from.


How to download a file using javascript

Posted: Tue Aug 13, 2013 9:42 pm
by Nayef

The result is :

After click the button
Popup window :

Title: Alert
ـــــــــــــــــــــــــــــــــــــــــــــــــــــ
download error source
http://www.mysite.com
/uploads/quickstart.pdf

____________________

ok

------------------ After Click ok
Title: Alert
ـــــــــــــــــــــــــــــــــــــــــــــــــــــ
download error target
file://sdcard/quickstart.pdf

____________________

ok

------------------ After Click 2nd ok
Title: Alert
ـــــــــــــــــــــــــــــــــــــــــــــــــــــ
upload error code3

____________________

ok

------------------ After Click 3rd ok nothing happened

The code used :

var fileTransfer = new FileTransfer();
var filePath = "file://sdcard/quickstart.pdf";
var uri = encodeURI("http://www.mysite.com/uploads/quickst...");

fileTransfer.download(
uri,
filePath,
function(entry) {
alert("download complete: " + entry.fullPath);
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
},
false,
{
headers: {
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);


How to download a file using javascript

Posted: Wed Aug 14, 2013 6:00 am
by Maryna Brodina

Hi,

1) let's check first if your app downloads any file. Try to download some PDF file when you don't need authorization, for example http://samplepdf.com/sample.pdf

2) please ensure you use correct login and password. Are you able to retrieve your PDF file using curl command? If so could you clarify what curl request parameters you use?


How to download a file using javascript

Posted: Sat Aug 17, 2013 1:35 pm
by Nayef

I replaced the link and it's working now

Only : Onclick navgate to link

The problem is from my site ):