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: 
JohnBasedow
Visitor

Content-type: multipart Possible?

I'm trying to figure out how to add multipart headers for a multipart form-data form using a roUrlTransfer object.

The problem is that you need to separate each of the "parts" with a boundary, and the requisite newlines need to be there between sections. If I try to fudge these headers by adding the newlines myself, the header gets rejected, and doesn't make it to the server.

Is there any way to build a multipart header, without implementing this myself?
0 Kudos
3 REPLIES 3
EnTerr
Roku Guru

Re: Content-type: multipart Possible?

Based on skimming this http://www.w3.org/TR/html401/interact/f ... -17.13.4.2 , I think you should add this header to roUrlTransfer
Content-Type: multipart/form-data; boundary=AaB03x

and then manually assemble the rest and post it as a body:
--AaB03x
Content-Disposition: form-data; name="submit-name"

Larry
--AaB03x
Content-Disposition: form-data; name="files"; filename="file1.txt"
Content-Type: text/plain

... contents of file1.txt ...
--AaB03x--

I am not clear on how were you fudging but the way i understand it, there is no "multipart header" - instead is a multipart request (with a single header).
0 Kudos
JohnBasedow
Visitor

Re: Content-type: multipart Possible?

Your response makes sense -- any clue how to mix ASCII and byte data when building the body? (As far as the Roku API is concerned)
0 Kudos
JohnBasedow
Visitor

Re: Content-type: multipart Possible?

Awesome -- thanks for your clarification!

I was able to accomplish this by creating the body like you mentioned in a String then loading it into an roByteArray, and writing it to a temp file
Then I load my binary file into an roByteArray and use AppendFile to append the contents to the first file
I then append the final boundary String bytes (Boundary + "--" + Chr(13) + Chr(10) + Chr(13) + Chr(10)) to that same file

The final step is to use AsyncPostFromFile with that temporary file.

Thanks again!
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.