'Apache bench test POST with image file contents
I have a web service that accepts image files via http POST, I send them with curl, for example:
curl -X POST -F "[email protected]" -F "[email protected]" http://domain.tld/upload
I'm trying to test this with apache bench (ab) for concurrent requests.
I see that ab has the option -p to post data but I think this requires JSON content... I tried to encode my images into JSON using the postman echo service :
curl -X POST -F "[email protected]" -F "[email protected]" http://www.postman-echo.com/post
save the output to file, and send that with ab's -p option, but gen a server error.
Any hints on how to test POSTing images with apache bench?
Solution 1:[1]
Did you try it with setting content-type?
ab -n 1 -p post -T application/x-www-form-urlencoded -p ta1.jpeg http://domain.tld/upload
When you tried to post json file, you'll want to set the json content-type:
ab -n 1 -p post -T application/json -p ta1.json http://domain.tld/upload
Solution 2:[2]
- Create a Post file.
For example, create file images.txt. Ensure that the line break is CRLF
--1234567890
Content-Disposition: form-data; name="file"; filename="text1.jpeg"
Content-Type: image/jpeg
[base64 encoded image]
--1234567890
Content-Disposition: form-data; name="file"; filename="text2.png"
Content-Type: image/png
[base64 encoded image]
--1234567890--
- Script
ab -c 1 -n 1 -v 4 -H "Accept-Encoding: gzip, deflate" -T "multipart/form-data; boundary=1234567890" -p "images.txt" "http://url"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | runwuf |
| Solution 2 | Oyedeji Peace |
