Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Level 7

Programmatically get photo from URL for roSlideShow?

I have a .NET app that returns a photo by passing url parameters to a page such as:

/getfile.aspx?photo=dog

This page returns a .png image file format by writing it to the HTTP response stream. Works fine using a browser to navigate to the URL, but doesn't seem to work as a valid URL for my roSlideShow object. I've tried:

Response.ContentType = "image/png";

and

Response.AddHeader("Content-Disposition", "inline; filename = \"myimage.png\"");

to no avail. Any ideas? Am I using the right content disposition?

Thanks in advance!
0 Kudos
9 Replies
Highlighted
Level 8

Re: Programmatically get photo from URL for roSlideShow?

Are you writing the bytes[] to the client from a stream or returning a url path.

if bytes[] be sure to use Binary write. Lot's of examples out there.

if the image is an actual url just do a redirect or transfer.

Test it in a broswer 1st would be my advice...
0 Kudos
Highlighted
Level 7

Re: Programmatically get photo from URL for roSlideShow?

Thank you for your reply. Yes, I'm placing my image into a MemoryStream and then writing it to the HTTP response using BinaryWrite(). Here's more of my code, so you can see what I'm doing. Again, if I use a browser to navigate to the URL, I get a valid .png image. If I use this same URL for my roSlideShow photo, no image is rendered.

MemoryStream ms = new MemoryStream();
imgResult.Save(ms, ImageFormat.Png); //imgResult is a System.Drawing.Bitmap

Response.Clear();
Response.ContentType = "image/png";
Response.AddHeader("Content-Disposition", "inline; filename = \"myimage.png\"");
Response.BinaryWrite(ms.ToArray());
Response.End();

It seems like this would be a common need for developers who are trying to get images (or other media) from a database. Any more ideas?
0 Kudos
Highlighted
Level 7

Re: Programmatically get photo from URL for roSlideShow?

UPDATE:

I tried saving the image to the file system, then using Response.Redirect() to point to the file. I've also tried Server.Transfer() to point to the file. Again, all of these methods work fine just using a web browser and return my .png image. When my brightscript code requests the URL, it apparently tries 3 times because 3 image files are created in the file system; however, the image is never displayed by my roSlideShow object.

Any ideas out there?

Thanks in advance,

S
0 Kudos
Highlighted
Level 8

Re: Programmatically get photo from URL for roSlideShow?

Make sure you are not using get Url with timeout or increase the timeout value in the helper function.
0 Kudos
Highlighted
Level 7

Re: Programmatically get photo from URL for roSlideShow?

get URL? I don't think I'm using that anywhere. Perhaps that's what I'm missing? I'm testing with a simple array of 1 associative array item. Here's a simplified version of my brightscript code:


Function showPageScreen(slideshow As Object) As Integer
contentArray = CreateObject("roArray", 10, true)
aa = CreateObject("roAssociativeArray")
'aa.Url = "http://www.[mysite].com/myimage.png" <-- This works when uncommented (albeit, it takes ~30 seconds to display the image)
aa.Url = "http://www.[mysite].com/getimage.aspx?img=1" <-- This is what I'm trying to get to work
contentArray.Push(aa)
slideshow.SetContentList(contentArray)
slideshow.Show()
while true
msg = wait(0, slideshow.GetMessagePort())
if type(msg) = "roSlideShowEvent" then
if msg.isScreenClosed() then
return -1
end if
end if
end while
return 0
End Function


What am I missing/doing wrong here? I think if I can get this simple example to work, I'll be off to the races. Smiley Happy Thanks in advance for any other suggestions you can offer,

S
0 Kudos
Highlighted
Level 8

Re: Programmatically get photo from URL for roSlideShow?

I think EngoTom was thinking you were retrieving the image via the roUrlTransfer component, which actually offers another possibility. You could use the GetToFile method of the roUrlTransfer component to save the image to a "tmp:/" path, and then set the Url of the slideshow content to that local path. Seems a bit of a long route to take, but it should work if your direct URL doesn't.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Highlighted
Level 7

Re: Programmatically get photo from URL for roSlideShow?

Ok, I experimented with roUrlTransfer a bit, but no luck. So, I tried using the roImageCanvas component - success!! This component will allow me to provide a URL value that doesn't point directly to a .png file. Hopefully, I'll be able to do everything I want to do using this component. Thank you for your suggestions and advice!

S
0 Kudos
Highlighted
Level 9

Re: Programmatically get photo from URL for roSlideShow?

Glad you found a workaround by using roImageCanvas. I opened a bug against roSlideShow so that it doesn't require the url to end in .jpg or .png in the future.

--Kevin
0 Kudos
Highlighted
Level 7

Re: Programmatically get photo from URL for roSlideShow?

Just a thought, but it the URL is required to end in a .jpg or .png, did you try adding a dummy parameter at the end to fool the Roku component?
E.g. if you want
/getfile.aspx?photo=dog

then request
/getfile.aspx?photo=dog&dummy=file.png


As long as your .NET app is lenient towards unknown parameters, and if the Roku component really just cares that the supplied full (GET) URL ends in .png or .jpg, that might work.
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos