Toblerone
Posts: 0
Joined: Wed Aug 07, 2013 5:08 pm

Download file?

Hi all,

I'm wanting to download some files on first load for my app (some music files), i had a look at a post here

https://getsatisfaction.com/apperyio/...

But that doesn't work, just giving me an error about

Uncaught ReferenceError: FileTransfer is not defined

Also that example seems to hard-code destination as sdcard.

So I have 2 quetions

1) Does anyone have any working tutorial on downloading a file (with some success/fil handling)

2) How do i get a path to the documents folder for my app as I dont want to store on /sdcard (which wont exist on iOS anyway).

Thanks you

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Download file?

Hello,

[quote:]
But that doesn't work, just giving me an error about

Uncaught ReferenceError: FileTransfer is not defined
[/quote]

Please show us your code.

  1. Unfortunately we don't have such tutorial. You can use PhoneGap API or some JS libraries to download the files.

  2. Where do you want to store the files?

Toblerone
Posts: 0
Joined: Wed Aug 07, 2013 5:08 pm

Download file?

I want to store the files in the documents folder for the app (applicationDocumentsDirectory/ NSDOcumentsDirectory for ios, on android the equiv of applicationInfo.dataDir;)

How do I share the app with you, you can easily just copy the code from the link above and see the error, just add code to page load.

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Download file?

You could use PhoneGap API to store the files.
Code from the link above (PhoneGap API) works only on device. Please try to test on device.

Toblerone
Posts: 0
Joined: Wed Aug 07, 2013 5:08 pm

Download file?

Thanks Igor,

One final question, how do I actually download a file from appery back-end database then? I can't any examples on doing that on the database tutorials?

Toblerone
Posts: 0
Joined: Wed Aug 07, 2013 5:08 pm

Download file?

I tried this on device, i still get a FileTransfer is not defined exception.

Do you actually have a working example of downloading a file from appery?

Toblerone
Posts: 0
Joined: Wed Aug 07, 2013 5:08 pm

Download file?

And here is the code I used, simply put in startScreen's "Page show" event, it never reaches the alert('done') part. (url edited + dbid removed)

alert('making new filetransfer()');
try {
var fileTransfer = new FileTransfer();
alert('done..'); // never reaches here
var uri = encodeURI("https://api.appery.io/rest/1/db/files...=");
alert('getting ur ' + uri);

Code: Select all

 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: { 
             "X-Appery-Database-ID": "" 
         } 
     } 
 ); 
 alert('done'); 

}
catch (ex)
{
alert('exception ' + ex.message); // always ends up in here
}

Toblerone
Posts: 0
Joined: Wed Aug 07, 2013 5:08 pm

Download file?

OK managed to get the code running by putting it in device read event instead of page show... however, no matter waht file I try to download (picked some public mp3, some jpg, some text), always gives error 3 which is

FileTransferError.CONNECTION_ERR

Are there any restrictions with the appery tester which would cause this as I can't see any reason why it would fail, and seems there's no way to get to debug console from the tester to see anything useful?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Download file?

Hi Toby - just to clarify - you are testing it using Appery.io Tester?

[quote:]
FileTransferError.CONNECTION_ERR
[/quote]

this error is described in PhoneGap Docs

Return to “Issues”