roku not loading images

Hi, i’m having problems loading images, both on canvas component and using both getfile and asyncgetfile.

The canvas component doesnt show the images (sometimes) and the async/getfile finishes loading, but when i try to get the local file it doesn’t exist

There is a very erratic behavior, and after some tests i think it has got to do with image size (px/kb) and simoultaneous loading.

I started a java tomcat to use as proxy and monitor the image urls to be loaded by the canvas component. At first i started returning big images (2000x200 px 3Mb) created on the fly, and these loaded fine, until i started changing the images fast, and i started getting a connection reset by peer (roku) in the server, that could be one of the problems.

any ideas?

thanks!

I assume you are saving the files to tmp:/filename

so are you downloading multiple images to separate file names, or are you overwriting the image every time? You might want to grab a series, and then if you need to cleanup the tmp:/ area remove the oldest file.

The imageCanvas function is pretty slow to update, updates around 100 - 150 milliseconds. So Update, wait a bit, then update again.

For faster image rendering use roScreen instead of image canvas (of course this depends on what you are trying to accomplish).

  • Joel

Thanks joel, i’ve been doing some more research on these images using firebug and loading them with js and html, and i got an http 302 status from the image and then it redirects to another url retrieveing the image.

How does roku handle http 302?

thanks!!

Joel, I tried using roScreen, but found no reference to it in the documentation, also i think it does not support the same methods roImageCanvas has…

ideas?

thanks!

roScreen is in the Brightscript reference.

-JT

“bmn” wrote:
Thanks joel, i’ve been doing some more research on these images using firebug and loading them with js and html, and i got an http 302 status from the image and then it redirects to another url retrieveing the image.

How does roku handle http 302?

thanks!!

There’s a resolveRedirect function in the MRSS template, see if that will work for you.

  • Joel

Joel thanks for your reply! but i stil couldnt load…

ahttp=CreateObject(“roUrlTransfer”)
ahttp.EnableEncodings(true)

ahttp.AddHeader(“user-agent”, “Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3”)
'ahttp.SetUrl(url)

port = CreateObject(“roMessagePort”)
ahttp.setPort(port)
result = invalid

done = false

while not done
ahttp.SetURL(url)
result = ahttp.AsyncGetToFile(filename)
if ahttp.AsyncHead()
while true
msg = wait(10000, ahttp.GetPort())

if msg <> invalid
h = msg.GetResponseHeaders()
PrintAA(h)
if ValidStr(h.location) <> “”
result = ValidStr(h.location)
else
done = true
end if
else
done = true
end if
exit while
end while
else
done = true
end if

end while
print “IMAGE LOADED TO FILE”
return result

the print image loaded to file appears, but when i check for the file it isnt there…

is the code i wrote correct? any more ideas?

thanks!!

Joel, shouldnt the Canvas SetLayer handle this images well? I mean shouldt the component handle the 302 message?

I’m really out of ideas here…

Joel got more crazy things now..

I started getting a 403 error now, not the 302 firefox received… so I changed the code to get the headers, i got to the target and then i should recall the thing again..

the problem is i am getting status 200 now, it just returns crazy values! could it be cache?

port = CreateObject(“roMessagePort”)
ahttp.setPort(port)
result = invalid
result = ahttp.AsyncGetToFile(filename)
while true
msg = wait(100, ahttp.GetPort())
if type(msg)=“roUrlEvent”
print “status code”
print msg.GetResponseCode()
if msg.GetResponseCode() = 403 then
headers=msg.GetResponseHeadersArray()
for each h in headers
if h.Location <> invalid
url=h.Location
goto start
end if
next
exit while
end if
if msg.GetResponseCode() = 200 then
exit while
end if
end if
end while

I managed to get the Target header, which was returned in the 403 http error, this header contains the path to the image, i tried loading that image, and even though the http status is 200,the image is not shown…

Why could this happen?

I may be wrong, but I believe that roUrlTransfer automatically handles HTTP redirects (302). The underlying cUrl library should take care of that for you. There shouldn’t be any need to read the headers yourself and send off another request for the redirected url.

In the first code you posted, you called AsyncGetToFile immediately followed by a call to AsyncHead, so you’re issuing two simultaneous asynchronous requests to the same url, one for the whole file and one for just the headers. If the AsyncHead request completes first, your loop terminates before the AsyncGetToFile request completes, so you have no way of knowing whether the AsyncGetToFile call completed successfully.

In the last code you posted, if you get a 403 error that means that your access to that resource is forbidden; you won’t be able to read it due to some security violation.

I would use something like this to do what you’re trying to do:

Function getImageToFile(url As String, filename As String, timeout As Integer) As Boolean
	ahttp = CreateObject("roUrlTransfer")
	port = CreateObject("roMessagePort")
	ahttp.SetPort(port)
	ahttp.SetUrl(url)
	ahttp.AddHeader("User-Agent", "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3")
	ahttp.EnableEncodings(True)

	result = ahttp.AsyncGetToFile(filename)
	If result
		While True
			msg = Wait(timeout, port)
			If Type(msg) = "roUrlEvent"
				Print "AsyncGetToString: msg.GetResponseCode() = " + msg.GetResponseCode().ToStr () + ". msg.GetFailureReason () = " + msg.GetFailureReason ()
				If msg.GetResponseCode() <> 200
					result = False
				Endif
				Exit While
			Else If Type (msg) = "Invalid"
				Print "AsyncGetToString: timeout"
				ahttp.AsyncCancel()
				result = False
				Exit While
			Else
				Print "AsyncGetToString: Unknown event: " + Type (msg)
			Endif
		End While
	Endif

	Return result

End Function

Also, when posting code in the forums, it’s a lot easier to read if you enclose your code in “Code” tags. (Just click the “Code” button above the text entry box then insert your code between the code and /code tags).

Belltown, thanks for your reply! hey i tried that code but still no luck, i get:

“AsyncGetToString: timeout”

but when i try to load the url through firefox, the image loads fine..

why could this be?

Have you tried calling it with a timeout value of zero? And are you able to load other images from other locations using the same code?

See if this works, for example:


if getImageToFile("http://blog.roku.com/wp-content/uploads/2012/01/fan_o_da_month1.jpg", "tmp:/test.jpg", 0)
    print "Image Loaded"
else
    print "Image failed to load"
endif

Belltown, yes i tried loading other images from other sites, and they work fine, not only did i load them using the code i submitted but also using the canvas component.

But these other images load fine in firefox, and the only difference with a simple http call is this 302 redirect thing…

Well i also tried retrieving the image the http header:target of the 302 redirect has, which would be the actual image, and it doesnt even load that one…

Im really lost here…

belltown, i did some more testing.. i used your first code, and what i did was to load the images to be loaded by the canvas component before this one loads them, so they would be cached…

now I’m getting:

AsyncGetToString: msg.GetResponseCode() = 200. msg.GetFailureReason () = OK

so they seem to have loaded.. but canvas does not show them…

this is getting most weird!

Well there were some issues regarding the firewall, apparently the image url was blocked for roku because it wasnt authentified… either way roku is not handling the redirect automatically…so this error should be taken care manually

has anyone an idea different to load the url asynchronically and get the http header? perhaps some configuration?

thanks!

Sorry about all the fuzz… we were having some problems with the firewall..

sorry, and thanks a lot!