Search code examples
jmetermultipartform-data

jMeter multipart request with file upload


I have a multipart request that I construct. Each part of the request is a jsonString body and it has a set of headers for the whole request and some for individual multiaprts.

I can use jMeter's 'Send parameters with request' to add Name-value for the jsonStrings, but I cannot specify headers within each of these parts. I can specify a header manager for the entire request, but can it be specified for each of the multiparts as well?

Also, while specifying the content to upload, I have a file whose contents are compressed and encoded into bytes by a JSR223 Sampler and I would want this to be sent along with the request.


Solution

  • You can build the request manually, just take the following steps:

    1. Uncheck Use multipart/form-data for HTTP POST box in the HTTP Request Sampler
    2. Add HTTP Header Manager as a child of the HTTP Request Sampler and configure it to send Content-Type header with the value of multipart/form-data; boundary=your_custom_boundary
    3. Switch to "Body Data" tab of the HTTP Request Sampler and construct your request body there separating each parameter set with

      --your_custom_boundary
      

    See Testing REST API File Uploads in JMeter guide for a little bit more detailed explanation and demo.