Home > Enterprise >  Jmeter post multipart form data with string
Jmeter post multipart form data with string

Time:01-08

I am trying to upload file with string in JMeter. It doesn't work

POST http://localhost:8080/upload

POST data:
--v2IM1VsVLV5EbtspRzGOSrHaDQb-mlef6r
Content-Disposition: form-data; name="input"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

{   "name": "John",  "country": "US" }

--v2IM1VsVLV5EbtspRzGOSrHaDQb-mlef6r
Content-Disposition: form-data; name="file"; filename="sample.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

<actual file content, not shown here>
--v2IM1VsVLV5EbtspRzGOSrHaDQb-mlef6r--


[no cookies]

I got the following error using JMeter

{"code":"ERROR","message":"Required request parameter 'input' for method parameter type String is not present"}

I am able to hit the request using curl or Postman without any issues. Here is my curl request.

curl -i -X POST \
   -H "Content-Type:multipart/form-data" \
   -F "file=@\"./sample.txt\";type=text/plain;filename=\"sample.txt\"" \
   -F "input={   \"name\": \"John\",  \"country\": "US" }" \
 'http://localhost:8080/upload'

CodePudding user response:

If you're able to execute the request successfully using Postman you should be able to record the request using JMeter's enter image description here

  • Copy the sample.txt file to "bin" folder of your JMeter installation

  • Run your request in Postman

  • JMeter will capture the request and generated proper HTTP Request sampler

  • More information: How to Convert Your Postman API Tests to JMeter for Scaling

    •  Tags:  
    • Related