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: 

Download contents of POST request to file

I'm working on a Roku app that displays MJPEG videos. This is a little bit tricky because as far as I can tell there isn't really a way to handle a generic stream over HTTP in Brightscript. What I've done that works is initiate a download with roUrlTransfer.AsyncGetToFile. I can then process the tmp file that is created as the MJPEG is continuously downloaded. I have to clean up the file and restart the transfer every once in awhile to avoid overflowing the storage space, but it works well enough.

The problem I'm having is that one of the sources I need to support requires that I POST some session information in order to pull down the MJPEG I need to display. As far as I can tell roUrlTransfer doesn't provide a way to POST a string and save the result as a file. Is there a way to accomplish this that I'm not seeing? Even better, is there a way to process an HTTP response as it comes instead of all-at-once when it completes?

* Edited to reflect that I'm currently using AsyncGetToFile not GetToFile
0 Kudos
6 REPLIES 6
EnTerr
Roku Guru

Re: Download contents of POST request to file

Now you are at the right place. Let's see what roMavens have to say.

As banter on the side (i am clueless on ro-async specifics), i guess you are trying to handle webcam stream of M-JPEG over HTTP kind? Since that's infinite stream, in a perfect world there'd be some kind of support for chunked http response where you receive roUrlEvent with each chunk but i don't see that in the docs.

Here are related topics i looked up: viewtopic.php?f=34&t=73569 and viewtopic.php?f=34&t=57776

This is an interesting one: viewtopic.php?f=34&t=34740&start=15#p384526 - seems you might be able to use roUrlRequest.setRequest(method) to change the verb that say AsyncGet will use.
0 Kudos
RokuMarkn
Visitor

Re: Download contents of POST request to file

There isn't any way to process an HTTP stream incrementally.
To read the response to a POST, use an AsyncPostFrom{File,String} and read the response when you get the roUrlEvent.

--Mark
0 Kudos

Re: Download contents of POST request to file

Mark,
The MJPEG stream is continuous so there is never an roUrlEvent. The request never actually completes and as far as I've seen roUrlEvents are only returned on completion.

Aaron
0 Kudos

Re: Download contents of POST request to file

EnTerr,
Thank you for finding these posts for me. I looked a bit at setRequestMethod awhile back, but unfortunately it leaves me with the same problem: I can set the method to POST and then AsyncGetToFile, but as far as I can tell this doesn't provide me with a way to set the HTTP request body for my GET turned POST request.

Aaron
0 Kudos
RokuMarkn
Visitor

Re: Download contents of POST request to file

I see, I didn't realize the POST and the stream response were the same query.
Does the server support byte-range requests? Perhaps you could split your query into a number of separate byte-range queries.

--Mark
0 Kudos
RokuJoel
Binge Watcher

Re: Download contents of POST request to file

"fireandlight27" wrote:
The problem I'm having is that one of the sources I need to support requires that I POST some session information in order to pull down the MJPEG I need to display. As far as I can tell roUrlTransfer doesn't provide a way to POST a string and save the result as a file.


Well, there is now:

   asyncPostFromFileToFile(SourceFile,Destfile)


Not yet documented. I don't think this works on legacy (3.x) firmware though I can't confirm that right now.

Is there a way to accomplish this that I'm not seeing? Even better, is there a way to process an HTTP response as it comes instead of all-at-once when it completes?


Unfortunately, not yet, as far as I'm aware.

- Joel
0 Kudos