Posting FileList in RestAssured

Currently I use the below code to post single file using RestAssured.

RestAssured.given().contentType(ContentType.MULTIPART_FORM_DATA.toString()).request().multiPart("files", ScreenshotFile).post().then().statusCode(200);

However I want to upload multiple files from the below mentioned FileList.

File ScreenShotFolder  = new File("C:\Users\1451615\Desktop\SessionScreenshot\");
File ScreenShotFiles[] = ScreenShotFolder.listFiles();


I have put a for loop to post multiple files in the same request. Please find below the code for same.

File ScreenShotFolder = new File(“C:Users1451615DesktopSessionScreenshot”); File ScreenShotFiles[] = ScreenShotFolder.listFiles(); RestAssured.baseURI =””; RequestSpecification request = RestAssured.given().contentType( ContentType.MULTIPART_FORM_DATA.toString()).request(); for(File file : ScreenShotFiles) { System.out.println(“File name: “+file.getName()); String FilePath = file.getAbsolutePath(); File ScreenShotPath = new File( FilePath ); System.out.println(ScreenShotPath); request.multiPart( “files”, ScreenShotPath );

    } 200 );

Leave a Reply

Your email address will not be published. Required fields are marked *