Based on this question with some adjustments https://stackoverflow.com/questions/20220270/posting-multipart-form-data-with-apache-bench-ab
You'll need a text file post_data.txt
with the following contents:
--1234567890
Content-Disposition: form-data; name="file"; filename="ab1_pod.jpg"
Content-Type: application/jpeg
Content-Transfer-Encoding: base64
[base64 encoding of the file]
--1234567890--
I have added the line specifying a base64 encoding that was necessary.
To base64 encode your file you could do:
base64 yourfile.png >> post_data.txt
echo "--1234567890--" >> post_data.txt
Some tutorials mention switching to a windows style line ending:
unix2dos post_data.txt
I have not noticed that being necessary.
You can doublecheck with cat -e post_data.txt
the file should end in ^M$
Suppose you need authentication for your file upload, then you'll need to add that as a header in our case:
ab -v 4 -n 1 -c 1 -H 'Authorization: Bearer e...Y' -p post_data.txt -T "multipart/form-data; boundary=1234567890" http://localhost:9091/v1/images
-v 4 # this will give you a lot of useful info like the response from the server, useful for debugging
-n 1 # number of requests in total
-c 1 # number of concurrent requests -n 7 -c 5 will do 7 requests in total: first 5 then 2
You probably want to start with -n 1 -c 1
and then increase the numbers. It's also a good idea to try a GET first.
I use this method but I met an error, " malformed MIME header line". I have not found the reason and did not know how to solve it.