How to send form-data in api using Rest-assured

D Bhatnagar picture D Bhatnagar · Jan 15, 2018 · Viewed 13.7k times · Source

I want to send below as a form-data in API Body for a PUT request:

  1. Upload a file(KEY) with "Error.png"(VALUE)
  2. Send text, "MyName"(KEY) with false(VALUE)

How to do this using REST-Assured

Attached is the screenshot Form-Data Image

Answer

rohit.jaryal picture rohit.jaryal · Jan 18, 2018

You need to set desired content type i.e "multipart/form-data" and add the multipart request specs to the request. Eg.

        given()
            .contentType("multipart/form-data")
            .multiPart("file", "filename")
            .multiPart("key", "value")
            .when()
            .put(endpoint);