Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 809
user2626431 Avatar asked Aug 17 '16 22:08

user2626431


1 Answers

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.

like image 155
Dmitri T Avatar answered Nov 10 '22 01:11

Dmitri T