I have a problem with the network.download
Everything seems working until I want to access a file which should be downloaded into the system.DocumentsDirectory … when looking into the Directory there isn’t a file!
Here is my code:
local thelistis loadblacklist = function() local dothefilechecknow = function() local path= system.pathForFile( "blacklistedurls.json", system.DocumentsDirectory ) local file, errorString = io.open( path, "r" ) if not file then -- Error occurred; output the cause print( "Blacklist File error: " .. errorString ) return false else -- Read data from file local contents = file:read( "\*a" ) -- Decode JSON data into Lua table local t = json.decode( contents ) -- Close the file handle io.close( file ) -- Return table print ("new BLACKLIST now loaded!") return t end end local networkListener = function ( event ) if ( event.isError ) then print( "Network error - download failed: ", event.response ) -- blendoutplaybuttonandshowmessage() elseif ( event.phase == "began" ) then print( "Blacklist Progress Phase: began" ) elseif ( event.phase == "ended" ) then -- the files is now ready -- the file is now loaded print ("Blacklist Progress ended!") thelistis=dothefilechecknow() -- we now have a lua table -- usage: --[[ print (#thelistis) for x=1,#thelistis do print (thelistis[x].url) end --]] end end local params = {} params.progress = true network.download( "https://WEBSITE/DIRECTORY/blacklistedurls.json", "GET", networkListener, params, "blacklistedurls.json", system.DocumentsDirectory ) end
I always get the – Error occurred; output the cause print( "Blacklist File error: " … errorString )
error which is showing me the local path as errorString in the Simulator output.
What am I missing here?
When you look in the code the whole dothefilechecknow function is only called when the file has finished uploading… so why isn’t it in the directory then?