Hi, can’t find how to manage this problem with
network.download
In my app i have to download a sqlite db
it works fine and adding the random hash i manage to avoid the issue with
cache, i also manage the network issue so if there is no connection
or the site is down then error is catched. All ok until now.
Now the problem happens if the remote file does not exists… in this case
an empty file with the requested name is created anyway into the system.DocumentsDirectory
but as the app is going to open it i have an error of course.
Is there any way to test if remote file exist before downloading ?
Or maybe there is a way to catch the event about the remote file not existing ?
When it has been downloaded i cannot test if it is vaild for me…at that time
file has only the name of a db so i cannot check.
Thank you very much. Roberto
Here is my code
function buttonupdate:tap( event )
local myurl = "http://www.mysite.com/sqllite.db".."?"..tostring(math.random())
network.download( myurl, “GET”, networkListener, “sqllite.db”, system.DocumentsDirectory )
end
the network listener:
local function networkListener( event )
if ( event.isError ) then
native.showAlert(
“You need a data connection (Wifi or 3g)”,
“”,
{
"Ok ",
},
onShowFallitoClick
);
print ( “Network error - download failed” )
else
native.showAlert(
“Connection Completed”,
“”,
{
"Ok ",
},
onShowCompletatoClick
);
print(“done”)
end
print ( "RESPONSE: " … event.response )
end
[import]uid: 107268 topic_id: 30482 reply_id: 330482[/import]