Hi,
I am trying to perform a file upload as multipart/form-data in RestAssured but probably I am not sending the WebKitFormBoundary as part of the request.
The call works fine through the below utilities. (Hiding the details due to confidentiality purposes)
1. POSTMAN - Working
POST <my_url> HTTP/1.1
Host: <my_host_and_port>
<header_#_1> : <header_#_1_value>
<header_#_2> : <header_#_2_value>
Cache-Control: no-cache
Postman-Token: b43e49cf-0560-9909-7d54-ed55a278e0fc
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename=""
Content-Type:
----WebKitFormBoundary7MA4YWxkTrZu0gW
2. CURL - Working
curl -X POST -H "<header_#_1> : <header_#_1_value>" -H "<header_#_2> : <header_#_2_value>" -H "Cache-Control: no-cache" -H "Postman-Token: 58708f45-232e-e4d1-8dd7-1728e0c32a77" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "file=@<path_to_my_file>" "<my_url>"
3. REST-ASSURED - Not-Working
RestAssured.useRelaxedHTTPSValidation();
HashMap<String, String> my_headers1 = new HashMap<>();
my_headers1.put( xxxxx);
my_headers1.put( xxxxx);
RestAssured.baseURI = "xxxxx";
RestAssured.basePath = "xxxxx";
RestAssured.port = xxxxx;
File myfile = new File(xxxxx);
Response upload = given().
contentType("multipart/form-data").
multiPart("file",xccdfFile).
I am getting a 500 error code & an body stating "unsupported file type" (which is my developers are returning if they find any other file apart from a xml) while performing this upload.
As mentioned, the upload via the above 2 utilities works fine.
Could anyone please guide me as to what am I missing in my command.
Also I would like to understand how to generate the WebKitFormBoundary value in case of RestAssured, if that is the core-issue.
Thanks in advance.
Regards,
Rohan