Hi,
Thanks for the kind responses above.
I have tried the code below. It runs. But i cant seem to figure out where the output file question.jpg is saved. I tried to search in the Mac but couldnt find. Pls could you tell me how to figure out where the output is?
What if i want to display the output in the mobile screen instead? what code should i add?
Thanks
ttee
display.setStatusBar(display.HiddenStatusBar)
local path = system.pathForFile( “question.jpg”, system.CachesDirectory)
local myFile = io.open( path, “w” )
local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
elseif ( event.phase == “began” ) then
if event.bytesEstimated <= 0 then
print( “Download starting, size unknown” )
else
print( "Download starting, estimated size: " … event.bytesEstimated )
end
elseif ( event.phase == “progress” ) then
if event.bytesEstimated <= 0 then
print( "Download progress: " … event.bytesTransferred )
else
print( "Download progress: " … event.bytesTransferred … " of estimated: " … event.bytesEstimated )
end
elseif ( event.phase == “ended” ) then
print( "Download complete, total bytes transferred: " … event.bytesTransferred )
end
end
local params = {}
– This tells network.request() that we want the ‘began’ and ‘progress’ events…
params.progress = “download”
– This tells network.request() that we want the output to go to a file…
params.response = {
filename = “question.jpg”,
baseDirectory = system.DocumentsDirectory
}
network.request( “https://www.coronalabs.com/image.jpg”, “GET”, networkListener, params )
print(tostring(myFile))
local contents = “”
local file = io.open( path, “r” )
if file then
– read all contents of file into a string
local contents = file:read( “*a” )
io.close( file )
print(contents)
else
print(“file not found”)
end