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();

Answer

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 =”http://10.141.188.112:7080/PIMSelfService/testing/uploadResultImg”; 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 );

    }
       request.post().then().statusCode( 200 );

Leave a Reply

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