I’m using Ryan’s Cinder-Http block (using the UpdateBlock branch) for a current project at our studio. I’m trying to get my head around MultiPart Forms but can’t succeed. I’ve seen the source code and the part that is related to Multiparts but can’t figure out some stuff:
My task is to send a couple of jpeg photos along with some string data to an html form as follows
1- How to send a couple of jpegs in one part? In this case since the form accepts only one input for all the files (files[]), I think I need to do that. Or am I thinking wrong that the parts and html inputs are related somehow?
2- “Part” has an appendHeader() method. Are headers here equivilant to MIME “Content-Type” or is it something totally different? Is calling this method a must for each part or is it optional? I’m asking this since Multipart already has its header.
3- for each Part I should set the body as a Buffer, right? something like this ?
For future reference and others who might find it hard to grasp like me:
When I looked deeper into the block’s code, I realized that headers should be filled with the info you need for the subparts. That is besides the Content-Type: multipart/form-data; boundary and Content-Length headers which is set by the block for you. The header (which basically is a std::pair<string, string>) works in a way that the block puts a separator ‘:’ between its first and second value. So for instance to add the header Content-Disposition: form-data; name="text1" to your subpart you’d have to write:
Also when it comes to a file[] input in your form you can just send separate files to the same input name or you at the same time can specify the order of the files by appending the necessary headers. So for instance for the form I mentioned in my first post, I ended up with this code: