Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
belltown
Roku Guru

Re: roku not loading images

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).
0 Kudos
bmn
Visitor

Re: roku not loading images

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?
0 Kudos
belltown
Roku Guru

Re: roku not loading images

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
0 Kudos
bmn
Visitor

Re: roku not loading images

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...
0 Kudos
bmn
Visitor

Re: roku not loading images

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!
0 Kudos
bmn
Visitor

Re: roku not loading images

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!
0 Kudos
bmn
Visitor

Re: roku not loading images

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


sorry, and thanks a lot!
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.