Bashiul Alam Sabab
Bashiul Alam Sabab

Reputation: 17

Is there any way to upload an image file in the body of a HTTP POST request in Jmeter?

I have an API which requires an image along with few other parameters in its request body. In postman, the request parameters can be added in form-data (as shown in the attached image).

How can I implement it in Jmeter?

enter image description here

Upvotes: 0

Views: 760

Answers (2)

Dmitri T
Dmitri T

Reputation: 168237

Like this:

enter image description here

other parameters: userDataJson, requestReferenceId, etc. should go to "Parameters" tab.

Also be aware that given you can execute your request successfully in Postman you should be able to record it using JMeter's HTTP(S) Test Script Recorder.

  1. Configure Postman to use JMeter as the proxy

    enter image description here

  2. Copy the file(s) you will be uploading to the "bin" folder of your JMeter installation
  3. Execute request in Postman
  4. That's it, JMeter will capture the request and store the relevant HTTP Request sampler under the Recording Controller

Upvotes: 1

Ori Marko
Ori Marko

Reputation: 58902

Check Use multipart/form-data, add file in Files Upload tab and parameters in Parameters tab

if you are sending a file using a multipart form, the query string will be created using the multipart form specifications.

If it doesn't work you can use HTTP(S) Test Script Recorder while sending postman request

HTTP(S) Test Script Recorder allows JMeter to intercept and record your actions while you browse your web application with your normal browser. JMeter will create test sample objects and store them directly into your test plan as you go (so you can view samples interactively while you make them). Ensure you read this wiki page to setup correctly JMeter.

To use the recorder, add the HTTP(S) Test Script Recorder element. Right-click on the Test Plan element to get the Add menu: (Add → Non-Test Elements → HTTP(S) Test Script Recorder ).

Upvotes: 0

Related Questions