Page 1 of 1

Download file?

Posted: Mon Aug 26, 2013 11:05 am
by Toblerone

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


Download file?

Posted: Mon Aug 26, 2013 11:42 am
by Igor

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?


Download file?

Posted: Mon Aug 26, 2013 11:58 am
by Toblerone

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.


Download file?

Posted: Mon Aug 26, 2013 2:48 pm
by Igor

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.


Download file?

Posted: Mon Aug 26, 2013 3:55 pm
by Toblerone

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?


Download file?

Posted: Mon Aug 26, 2013 4:43 pm
by Toblerone

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?


Download file?

Posted: Mon Aug 26, 2013 4:49 pm
by Toblerone

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
}


Download file?

Posted: Mon Aug 26, 2013 5:37 pm
by Toblerone

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?


Download file?

Posted: Mon Aug 26, 2013 6:22 pm
by Illya Stepanov

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