user1981275
user1981275

Reputation: 13372

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?

Upvotes: 5

Views: 3611

Answers (2)

runwuf
runwuf

Reputation: 1719

Did you try it with setting content-type?

ab -n 1 -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 -T application/json -p ta1.json http://domain.tld/upload

Upvotes: 0

Oyedeji Peace
Oyedeji Peace

Reputation: 306

  • 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"

Upvotes: 0

Related Questions