0

I have a cURL that takes a file checksum and xml along with multiple headers in order to upload an image to a server. Im not very familiar with RestAssured so my question is; How do i represent the -F cURL values in RestAssured?

`curl -s -w "\nHTTP %{http_code}\n" -X POST ${mediaUrl}/api/user/${LCID}/repository/${REPO_NAME}/file?conflictSolve=copy \
-H "Accept: application/vnd.******.dv-1.19+xml" \
-H "Content-Type: multipart/form-data" \
-H "Authorization: *** token=\"${TOKEN}\"; authVersion=\"1.0\"" \
-H "x-******-***: ${TOKEN}" \
-H "X-Client-Identifier: TEST" \
-H "X-Client-Platform: CURL" \
-H "x-ingest-tag:RI" \
-F "files=@${XML};type=application/vnd.******.dv-1.19+xml" \
-F "${checksum}=@${file};type=${mimeType}"`

Currently i have progressed with the only the headers.

        Response response = given()
            .log().all()

            .spec(RestUtilities.get**RequestSpecification())    
            .header("Accept","application/vnd.******.dv-1.19+xml")
            .header("Content-Type", "multipart/form-data")
            .header("Authorization", "*** token=\""+access_token+"\"; authVersion=\"1.0\";")
            .header("x-*****-***", "access_token")

    .when()
        .post()
    .then()
    .log().all()
        .statusCode(200)
        .extract()
        .response();

}

}

Eamon M
  • 55
  • 2
  • 9

1 Answers1

0

The property curl -F will produce a request POST with datas using the Content-Type multipart/form-data http header.

So with RestAssured you have to call the method multipart (see the doc here) to upload the file.

Here an example :

 @Test
public void postMultipart() throws Exception {
    RestAssuredMockMvc.mockMvc(mockMvc);
    File xmlfile = resourceLoader.getResource("classpath:demo.xml").getFile();
    given()
            .log().all()
            .multiPart("files", xmlfile, "application/xml")
            .when()
            .post("/upload")
            .then()
            .log().all()
            .statusCode(200)
            .extract()
            .response();
}

So the param -F "files=@${XML};type=application/vnd.******.dv-1.19+xml" \

Can be convert to .multiPart("files", {YOUR-XML}, "application/vnd.******.dv-1.19+xml")

You can see the full source example in my Github

bdzzaid
  • 838
  • 8
  • 15