Here is another test I did. Basically I wrote a simplified file downloader and displayed the image. I also use the lfs to look at the System.DocumentsDirectory to see if the file is indeed downloaded and is of the right size and the log output says it is. But the display.newImage just doesnt work !
Here is the simplified function:
*************************************************************************************************************************************
function test_net(root)
local function networkListener( event )
print("NET RESPONSE = ", json.encode(event, {indent=true}))
if ( event.isError ) then
print( “NETWORK:: Network error - download failed” )
elseif ( event.phase == “began” ) then
print( “NETWORK:: Progress Phase: began” )
elseif ( event.phase == “ended” ) then
--local filename = system.pathForFile(event.response.filename, system.DocumentsDirectory,0,0 )
local filename = event.response.filename
print( “NETWORK:: Displaying response image file = " , filename, " basedir=”, event.response.baseDirectory)
--myImage = display.newImage( filename, event.response.baseDirectory, 60, 40 )
--myImage = display.newImage(filename, system.DocumentsDirectory, 50,50 )
myImage = display.newImage(“helloCopy2.txt” , system.DocumentsDirectory)
print(myImage.contentWidth)
--myImage.alpha = 0
--transition.to( myImage, { alpha=1.0 } )
root:insert(myImage)
myImage:toFront()
local doc_path = system.pathForFile( “”, system.DocumentsDirectory )
local k=1;
for file in lfs.dir(doc_path) do
--file is the current file or directory name
local attr = lfs.attributes(system.pathForFile(file, system.DocumentsDirectory ))
print(k, "Found file: " … file, " ", json.encode(attr) )
k = k + 1
end
end
end
local params = {}
headers = {
[“User-Agent”] = “Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0”,
[“Content-Type”] = “image/jpg”,
[“accept”] = “*/*”,
[“accept-charset”] = “*”,
[“Accept-Language”]= “en-US,en;q=0.5”,
[“Accept-Encoding”] = “gzip, deflate”,
}
params.progress = true
params.headers = headers
network.download(
– THE FIRST URL WORKS ALWAYS BUT THE SECOND DOES NOT WORK ON THE DEVICE !!
--"http://docs.coronalabs.com/images/simulator/image-mask-base2.png",
“[https://m.ak.fbcdn.net/profile.ak/hprofile-ak-xpf1/v/t1.0-1/c0.13.50.50/p50x50/1898067_10152047616577804_876002957_n.jpg?oh=577b4f540607eb16aaf9e37e6227b0f3&oe=54EFD211&__gda__=1424394365_30c2dab39230109502f30c76c53cfb6d”,](https://m.ak.fbcdn.net/profile.ak/hprofile-ak-xpf1/v/t1.0-1/c0.13.50.50/p50x50/1898067_10152047616577804_876002957_n.jpg?oh=577b4f540607eb16aaf9e37e6227b0f3&oe=54EFD211& gda =1424394365_30c2dab39230109502f30c76c53cfb6d)
“GET”,
networkListener,
params,
“helloCopy2.txt”,
system.DocumentsDirectory
)
end
******************************************************************************************************************************************************
And here is the dump
11-11 15:40:58.114: I/Corona(13803): NET RESPONSE = {
11-11 15:40:58.114: I/Corona(13803): “responseHeaders”:{
11-11 15:40:58.114: I/Corona(13803): “Access-Control-Allow-Origin”:"*",
11-11 15:40:58.114: I/Corona(13803): “Content-Length”:“1384”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Response-Source”:“NETWORK 200”,
11-11 15:40:58.114: I/Corona(13803): “Date”:“Tue, 11 Nov 2014 10:10:59 GMT”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Sent-Millis”:“1415700657608”,
11-11 15:40:58.114: I/Corona(13803): “Timing-Allow-Origin”:"*",
11-11 15:40:58.114: I/Corona(13803): “Expires”:“Tue, 25 Nov 2014 10:10:59 GMT”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Selected-Transport”:“http/1.1”,
11-11 15:40:58.114: I/Corona(13803): “Cache-Control”:“no-transform, max-age=1209600”,
11-11 15:40:58.114: I/Corona(13803): “Last-Modified”:“Tue, 25 Feb 2014 19:34:28 GMT”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Received-Millis”:“1415700658111”,
11-11 15:40:58.114: I/Corona(13803): “Content-Type”:“image/jpeg”,
11-11 15:40:58.114: I/Corona(13803): “HTTP-STATUS-LINE”:“HTTP/1.1 200 OK”,
11-11 15:40:58.114: I/Corona(13803): “Connection”:“keep-alive”
11-11 15:40:58.114: I/Corona(13803): },
11-11 15:40:58.114: I/Corona(13803): “phase”:“began”,
11-11 15:40:58.114: I/Corona(13803): “bytesEstimated”:1384,
11-11 15:40:58.114: I/Corona(13803): “name”:“networkRequest”,
11-11 15:40:58.114: I/Corona(13803): “bytesTransferred”:0,
11-11 15:40:58.114: I/Corona(13803): “status”:200,
11-11 15:40:58.114: I/Corona(13803): “url”:"[https://m.ak.fbcdn.net/profile.ak/hprofile-ak-xpf1/v/t1.0-1/c0.13.50.50/p50x50/1898067_10152047616577804_876002957_n.jpg?oh=577b4f540607eb16aaf9e37e6227b0f3&oe=54EFD211&__gda__=1424394365_30c2dab39230109502f30c76c53cfb6d",](https://m.ak.fbcdn.net/profile.ak/hprofile-ak-xpf1/v/t1.0-1/c0.13.50.50/p50x50/1898067_10152047616577804_876002957_n.jpg?oh=577b4f540607eb16aaf9e37e6227b0f3&oe=54EFD211& gda =1424394365_30c2dab39230109502f30c76c53cfb6d)
11-11 15:40:58.114: I/Corona(13803): “isError”:false,
11-11 15:40:58.114: I/Corona(13803): “requestId”:"<type ‘userdata’ is not supported by JSON.>"
11-11 15:40:58.114: I/Corona(13803): }
11-11 15:40:58.114: I/Corona(13803): NETWORK:: Progress Phase: began
11-11 15:40:58.114: I/Corona(13803): NET RESPONSE = {
11-11 15:40:58.114: I/Corona(13803): “responseHeaders”:{
11-11 15:40:58.114: I/Corona(13803): “Access-Control-Allow-Origin”:"*",
11-11 15:40:58.114: I/Corona(13803): “Content-Length”:“1384”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Response-Source”:“NETWORK 200”,
11-11 15:40:58.114: I/Corona(13803): “Date”:“Tue, 11 Nov 2014 10:10:59 GMT”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Sent-Millis”:“1415700657608”,
11-11 15:40:58.114: I/Corona(13803): “Timing-Allow-Origin”:"*",
11-11 15:40:58.114: I/Corona(13803): “Expires”:“Tue, 25 Nov 2014 10:10:59 GMT”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Selected-Transport”:“http/1.1”,
11-11 15:40:58.114: I/Corona(13803): “Cache-Control”:“no-transform, max-age=1209600”,
11-11 15:40:58.114: I/Corona(13803): “Last-Modified”:“Tue, 25 Feb 2014 19:34:28 GMT”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Received-Millis”:“1415700658111”,
11-11 15:40:58.114: I/Corona(13803): “Content-Type”:“image/jpeg”,
11-11 15:40:58.114: I/Corona(13803): “HTTP-STATUS-LINE”:“HTTP/1.1 200 OK”,
11-11 15:40:58.114: I/Corona(13803): “Connection”:“keep-alive”
11-11 15:40:58.114: I/Corona(13803): },
11-11 15:40:58.114: I/Corona(13803): “phase”:“progress”,
11-11 15:40:58.114: I/Corona(13803): “bytesEstimated”:1384,
11-11 15:40:58.114: I/Corona(13803): “name”:“networkRequest”,
11-11 15:40:58.114: I/Corona(13803): “bytesTransferred”:1024,
11-11 15:40:58.114: I/Corona(13803): “status”:200,
11-11 15:40:58.114: I/Corona(13803): “url”:"[https://m.ak.fbcdn.net/profile.ak/hprofile-ak-xpf1/v/t1.0-1/c0.13.50.50/p50x50/1898067_10152047616577804_876002957_n.jpg?oh=577b4f540607eb16aaf9e37e6227b0f3&oe=54EFD211&__gda__=1424394365_30c2dab39230109502f30c76c53cfb6d",](https://m.ak.fbcdn.net/profile.ak/hprofile-ak-xpf1/v/t1.0-1/c0.13.50.50/p50x50/1898067_10152047616577804_876002957_n.jpg?oh=577b4f540607eb16aaf9e37e6227b0f3&oe=54EFD211& gda =1424394365_30c2dab39230109502f30c76c53cfb6d)
11-11 15:40:58.114: I/Corona(13803): “isError”:false,
11-11 15:40:58.114: I/Corona(13803): “requestId”:"<type ‘userdata’ is not supported by JSON.>"
11-11 15:40:58.114: I/Corona(13803): }
11-11 15:40:58.114: I/Corona(13803): NET RESPONSE = {
11-11 15:40:58.114: I/Corona(13803): “responseHeaders”:{
11-11 15:40:58.114: I/Corona(13803): “Access-Control-Allow-Origin”:"*",
11-11 15:40:58.114: I/Corona(13803): “Content-Length”:“1384”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Response-Source”:“NETWORK 200”,
11-11 15:40:58.114: I/Corona(13803): “Date”:“Tue, 11 Nov 2014 10:10:59 GMT”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Sent-Millis”:“1415700657608”,
11-11 15:40:58.114: I/Corona(13803): “Timing-Allow-Origin”:"*",
11-11 15:40:58.114: I/Corona(13803): “Expires”:“Tue, 25 Nov 2014 10:10:59 GMT”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Selected-Transport”:“http/1.1”,
11-11 15:40:58.114: I/Corona(13803): “Cache-Control”:“no-transform, max-age=1209600”,
11-11 15:40:58.114: I/Corona(13803): “Last-Modified”:“Tue, 25 Feb 2014 19:34:28 GMT”,
11-11 15:40:58.114: I/Corona(13803): “X-Android-Received-Millis”:“1415700658111”,
11-11 15:40:58.114: I/Corona(13803): “Content-Type”:“image/jpeg”,
11-11 15:40:58.114: I/Corona(13803): “HTTP-STATUS-LINE”:“HTTP/1.1 200 OK”,
11-11 15:40:58.114: I/Corona(13803): “Connection”:“keep-alive”
11-11 15:40:58.114: I/Corona(13803): },
11-11 15:40:58.114: I/Corona(13803): “responseType”:“binary”,
11-11 15:40:58.114: I/Corona(13803): “phase”:“ended”,
11-11 15:40:58.114: I/Corona(13803): “bytesEstimated”:1384,
11-11 15:40:58.114: I/Corona(13803): “response”:{
11-11 15:40:58.114: I/Corona(13803): “fullPath”:"/data/data/com.sanjit.signtist/app_data/helloCopy2.txt",
11-11 15:40:58.114: I/Corona(13803): “filename”:“helloCopy2.txt”,
11-11 15:40:58.114: I/Corona(13803): “baseDirectory”:"<type ‘userdata’ is not supported by JSON.>"
11-11 15:40:58.114: I/Corona(13803): },
11-11 15:40:58.114: I/Corona(13803): “name”:“networkRequest”,
11-11 15:40:58.114: I/Corona(13803): “bytesTransferred”:1384,
11-11 15:40:58.114: I/Corona(13803): “status”:200,
11-11 15:40:58.114: I/Corona(13803): “url”:"[https://m.ak.fbcdn.net/profile.ak/hprofile-ak-xpf1/v/t1.0-1/c0.13.50.50/p50x50/1898067_10152047616577804_876002957_n.jpg?oh=577b4f540607eb16aaf9e37e6227b0f3&oe=54EFD211&__gda__=1424394365_30c2dab39230109502f30c76c53cfb6d",](https://m.ak.fbcdn.net/profile.ak/hprofile-ak-xpf1/v/t1.0-1/c0.13.50.50/p50x50/1898067_10152047616577804_876002957_n.jpg?oh=577b4f540607eb16aaf9e37e6227b0f3&oe=54EFD211& gda =1424394365_30c2dab39230109502f30c76c53cfb6d)
11-11 15:40:58.114: I/Corona(13803): “isError”:false,
11-11 15:40:58.114: I/Corona(13803): “requestId”:"<type ‘userdata’ is not supported by JSON.>"
11-11 15:40:58.114: I/Corona(13803): }
11-11 15:40:58.114: I/Corona(13803): NETWORK:: Displaying response image file = helloCopy2.txt basedir= userdata: 0x79729b71
11-11 15:40:58.124: I/Corona(13803): 0
11-11 15:40:58.124: I/Corona(13803): 1 Found file: . {“dev”:45852,“change”:1415700658,“access”:1415443286,“rdev”:0,“nlink”:2,“blksize”:4096,“permissions”:“rwxrwx–x”,“uid”:10213,“blocks”:8,“gid”:10213,“ino”:203833,“mode”:“directory”,“modification”:1415700658,“size”:4096}
11-11 15:40:58.124: I/Corona(13803): 2 Found file: … {“dev”:45852,“change”:1415700590,“access”:1415443275,“rdev”:0,“nlink”:7,“blksize”:4096,“permissions”:“rwxr-x–x”,“uid”:10213,“blocks”:8,“gid”:10213,“ino”:203790,“mode”:“directory”,“modification”:1415700590,“size”:4096}
11-11 15:40:58.124: I/Corona(13803): 3 Found file: helloCopy2.txt {“dev”:45852,“change”:1415700658,“access”:1415700658,“rdev”:0,“nlink”:1,“blksize”:4096,“permissions”:“rw-------”,“uid”:10213,“blocks”:8,“gid”:10213,“ino”:203604,“mode”:“file”,“modification”:1415700658,“size”:1384}
***********************************************************************
As you can see the print(myImage.contentWidth) printed 0. But the file is CLEARLY there in the directory (1384 bytes which is the correct size) !!
Please help !
Sanjit