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
<form method="post" action="postImage.php" enctype='multipart/form-data'> <input type='file' name='files' multiple="multiple" /><br /> <input type="number" name="id" placeholder="Machine ID"><br /> <input type="text" name="fname" placeholder="first name"><br /> <input type="text" name="lname" placeholder="last name"><br /> <input type="number" name="phone" placeholder="phone"><br /> <input type="email" name="email" placeholder="email"><br /> <input type='submit' value='Submit' name='but_upload'> </form>
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 ?
srand(time(NULL)); http::MultipartFormData formData(toString(rand())); http::MultipartFormData::Part part; string fileName ="test.jpg"; part.setBody(Buffer(loadFile(fileName))); formData.appendPart(std::move(part));
In general I think it’d be great for the block to have an example with multiparts.
Thanks a lot