1
votes

I'm trying to upload an image file using rest api jmeter but I'm getting a 400 bad request error. Below are the steps with the screenshots I've followed to upload a file:

enter image description here

Checked the multipart/form data option and sent the post body empty, under the send files with request, specified the path of the image file which I've placed in the jmeter/bin folder, set the parameter name as file which is from the request payload and MIME type as image/jpeg

enter image description here

Http Header Manager with the Authorization- value, Accept-Encoding- value, Connection-Keep Alive, If-Match-2

enter image description here

Result: Got 404 bad request

POST data:

--3yAYhmLPQ-1r98DX3NMZONHWXK0QDp4uuTmlQYEv
Content-Disposition: form-data; 
name="file"; 
filename="SampleJPGImage_2mbmb.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary

<actual file content, not shown here>
--3yAYhmLPQ-1r98DX3NMZONHWXK0QDp4uuTmlQYEv--
1
Inlined the imagesmkl

1 Answers

0
votes

HTTP Status Code 400 means that your request is malformed, it does not correspond to what your server expects.

You need to refer your API specification to figure out the correct request structure and amend JMeter configuration in order to exactly match it.

In case of REST API file upload it might not be enough to just send file with the request, you may have to build the request body manually. See Testing REST API File Uploads in JMeter article for an example of building POST and PUT requests to Google Drive API, it will give you some clue with regards to which direction to take.

You could also consider building the request using a 3rd-party tool like SoapUI or Postman which could be capable of constructing the request automatically and record it via JMeter's HTTP(S) Test Script Recorder