I'm creating a http server using uhttpd.
I'd like to upload a text file via POST or PUT.
I tried to upload two files using cURL like: curl -i -X PUT --form upload1=@myfile1.txt --form upload2=@myfile2.txt --form press=OK http://ip:port/test
and when I printed the body of request(api_request['http']['body']) I got like below:
b'--------------------------9f5122144448dcc5\r\nContent-Disposition: form-data; name="upload1"; filename="myfile1.txt"\r\nContent-Type: text/plain\r\n\r\n+++++++++++++++++++++++++++++++++++++++++++++++++++++\nfor uploading test\n++++++++++++++++++++++++++++++++++++++++++++++++++++\n\r\n--------------------------9f5122144448dcc5\r\nContent-Disposition: form-data; name="upload2"; filename="myfile2.txt"\r\nContent-Type: text/plain\r\n\r\n+++++++++++++++++++++++++++++++++++++++++++++++++++++\nfor uploading test\n++++++++++++++++++++++++++++++++++++++++++++++++++++\n\r\n--------------------------9f5122144448dcc5\r\nContent-Disposition: form-data; name="press"\r\n\r\nOK\r\n--------------------------9f5122144448dcc5--\r\n'
How could I extract the text in each form to save in string?
I have created a http server once using Flask and I wanted exactly like those in Flask, for example:
str1 = request.form['myfile1']
str2 = request.form['myfile2']
The body above is concrecated and divided with boundary(--------------------------9f5122144448dcc5) as I know.
Should I save that body in a string, classify three forms with that boundary and some loops manually?