File not downloading on Android

So I am creating a puzzle game, and each puzzle is created from data within an SQLite file.  These files are hosted on my server.  In the simulator everything works fine and the files get downloaded, however, on my Android device it does not work.  I haven’t tested this on an iOS device yet.  

Here is the download code:

local function downloadFile() local function networkListener( event ) if ( event.isError ) then print( "Network error - download failed" ) print("status in isError: " .. event.status) print("response in isError: " .. event.response) elseif ( event.phase == "began" ) then print( "Progress Phase: began") print("status in began: " .. event.status) print("response in began: " .. event.response) elseif ( event.phase == "ended" ) then print( "download successful" ) print("status in ended: " .. event.status) print("response in ened: " .. event.response) storyboard.gotoScene("scene-DailyGame") end end local params = {} params.progress = true if fileExists(myG.selectedDailyPuzzle, system.TemporaryDirectory) then print("file exists") storyboard.gotoScene("scene-DailyGame") else network.download( "http://www.myserverinfo.com/" .. myG.selectedDailyPuzzle, "GET", networkListener, params, myG.selectedDailyPuzzle, system.TemporaryDirectory ) end end

And this is what the logcat is showing me:

I/Corona ( 2625): Progress Phase: began I/Corona ( 2625): status in began: 200 I/Corona ( 2625): Network error - download failed I/Corona ( 2625): status in isError: 200

I thought 200 meant the file downloaded successfully?  Why is it reverting to the isError state?

What is the actual file name you’re trying to download?

Sometimes Android needs a few more headers setup to download text files that get gzipped by the server.   But your error seems to indicate that it started to download the file correctly (that is the web server found the file and started sending it out to you.  But later on perhaps a timeout or disconnect happened.

Do you have the progress downloads turned on?

Also we have to ask the dumb question.  You do have the INTERNET permission turned on in your build.settings?

    android =
    {
        usesPermissions =
        {
            “android.permission.INTERNET”,
        },
    },

Rob, yes that is how I have my build.settings (and confirmed by the prompt on app install).  The filenames are in this format: “2013731.sqlite”.  I don’t have progress turned on but I’ll try that next.  The files are only about 180kb so it seems weird for it to timeout/disconnect every time.  Also note this happens whether the device is connected via 4G or Wifi.  

This is with network.request and progress turned on:

I/Corona (24501): Download starting, estimated size: 163840 I/Corona (24501): Network error! I/Corona (24501): nil

I wonder if you’re hitting a problem similar to his post:

http://forums.coronalabs.com/topic/32967-networkrequest-failing-on-android-over-ssl/

You may need to tell Android to accept files that it doesn’t know the type of.

Seems as though it was a file type issue.  I ended up converting my SQLite db’s to json files, kept the download code the same, and now it all works.  I wonder if there is some limitation set by Android with regards to downloading SQLite files (worried about SQL injection perhaps?)

Perhaps.  I think it’s more likely that it didn’t know what to do with the mime type.  Or it was getting gzipped before it was getting sent or something like that.

What is the actual file name you’re trying to download?

Sometimes Android needs a few more headers setup to download text files that get gzipped by the server.   But your error seems to indicate that it started to download the file correctly (that is the web server found the file and started sending it out to you.  But later on perhaps a timeout or disconnect happened.

Do you have the progress downloads turned on?

Also we have to ask the dumb question.  You do have the INTERNET permission turned on in your build.settings?

    android =
    {
        usesPermissions =
        {
            “android.permission.INTERNET”,
        },
    },

Rob, yes that is how I have my build.settings (and confirmed by the prompt on app install).  The filenames are in this format: “2013731.sqlite”.  I don’t have progress turned on but I’ll try that next.  The files are only about 180kb so it seems weird for it to timeout/disconnect every time.  Also note this happens whether the device is connected via 4G or Wifi.  

This is with network.request and progress turned on:

I/Corona (24501): Download starting, estimated size: 163840 I/Corona (24501): Network error! I/Corona (24501): nil

I wonder if you’re hitting a problem similar to his post:

http://forums.coronalabs.com/topic/32967-networkrequest-failing-on-android-over-ssl/

You may need to tell Android to accept files that it doesn’t know the type of.

Seems as though it was a file type issue.  I ended up converting my SQLite db’s to json files, kept the download code the same, and now it all works.  I wonder if there is some limitation set by Android with regards to downloading SQLite files (worried about SQL injection perhaps?)

Perhaps.  I think it’s more likely that it didn’t know what to do with the mime type.  Or it was getting gzipped before it was getting sent or something like that.