Reputation: 13
I am using 2 multiparts ( 1 is a file the other is a form-data )
For the file I am using the default content type but (multipart/form-data) but for the other I need to use application/json
I don't know how to set content type for that specific multipart/fpr, data ===
This is what I have done -
Response resp = RestAssured.given().baseUri(UPLOAD)
.header("Content-Type", "multipart/form-data; boundary=--abcd")
.multiPart("files",new File(System.getProperty("user.dir") +picPath))
.multiPart("JSON_DATA",JSON_DATA )
.post().then().extract().response();
But this is the request that has been generated --
Content-Disposition: form-data; boundary=--abcd; name = files; filename =Photo.png
Content-Type: application/octet-stream
/../../../Photo.png
------------
Content-Disposition: form-data; boundary=--abcd; name = JSON_Data; filename = file
**Content-Type: text/plain**
{.......}
HOW DO I SET THE 2ND ONE TO application/json instead of text/plainm
Upvotes: 1
Views: 1243
Reputation: 5917
You can define content-type for each part like this, no need put form-data
in header
given().log().all()
.multiPart("file", file)
.multiPart("JSON_DATA", JSON_DATA, "application/json")
.post();
Upvotes: 1