0

I need to upload multiple files using REST-assured, a Java DSL for easy testing of REST services. I succeeded to upload a single file. But I am not able to upload mutliple files. Can someone help me to upload multiple files in one request?

Example of a single file upload:

RestAssured.given().auth().oauth2(acessToken)
  .multiPart("file",new File("temp.pdf"),"application/pdf")
  .when().post("https://www.example.com").then().log().all();
cachius
  • 1,743
  • 1
  • 8
  • 21
Sai
  • 389
  • 6
  • 18
  • 1
    Does this answer your question? [How to pass multiple files as a input to an api using Rest Assured](https://stackoverflow.com/questions/62995600/how-to-pass-multiple-files-as-a-input-to-an-api-using-rest-assured) – cachius Dec 08 '20 at 14:53

2 Answers2

0

According to the docs

It's also possible to supply multiple "multi-parts" entities in the same request

by chaining several multiPart() method calls in a row:

RestAssured.given().auth().oauth2(acessToken)
  .multiPart("file",new File("temp.pdf"),"application/pdf")
  .multiPart("file",new File("readme.txt"),"text/plain")
  .when().post("https://www.example.com").then().log().all();
cachius
  • 1,743
  • 1
  • 8
  • 21
  • Thank you so much for the reply i followed the below URL it helpmed me to upload the n numbet of files – Sai Aug 26 '20 at 13:06
0

AS per the below link How to pass multiple files as a input to an api using Rest Assured we are able to upload multiple file successfully How to pass multiple files as a input to an api using Rest Assured

public static void main(String[] args) throws MalformedURLException {

    Response response;
    RequestSpecification request = RestAssured.given().header("content-type", "multipart/form-data");
    for (int i = 1; i <= 2; i++) {
        request.multiPart("file", new File("D:/testtemplates98_" + i + "Data.xlsx"));// File parameters will be
                                                                                        // dynamic
    }
    response = request.post(new URL("https://jquery-file-upload.appspot.com/"));
    System.out.println(response.getBody().asString());

}

Sai
  • 389
  • 6
  • 18