首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FileList在RestAssured中发布

FileList在RestAssured中发布
EN

Stack Overflow用户
提问于 2021-03-17 12:05:29
回答 2查看 63关注 0票数 0

目前,我使用下面的代码使用RestAssured发布单个文件。

代码语言:javascript
复制
RestAssured.given().contentType(ContentType.MULTIPART_FORM_DATA.toString()).request().multiPart("files", ScreenshotFile).post().then().statusCode(200);

但是,我想从下面提到的FileList上传多个文件。

代码语言:javascript
复制
File ScreenShotFolder  = new File("C:\\Users\\1451615\\Desktop\\SessionScreenshot\\");
File ScreenShotFiles[] = ScreenShotFolder.listFiles();
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-17 16:11:07

我已经放置了一个for循环来在同一个请求中发布多个文件。请在下面找到相同的代码。

代码语言:javascript
复制
File ScreenShotFolder = new File("C:\\Users\\1451615\\Desktop\\SessionScreenshot\\");
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);
票数 1
EN

Stack Overflow用户

发布于 2021-03-20 09:42:38

代码语言:javascript
复制
ValidatableResponse createAttachemnetResponse = expect()
                .given()
                .spec(requestSpecification)
                .header("content-type", "multipart/form-data")
                .multiPart("files-0", new File("testImages/1.jpg"))
                .multiPart("files-1", new File("testImages/2.png"))
                .multiPart("files-2", new File("testImages/3.png"))
                .multiPart("files-3", new File("testImages/4.png"))
                .multiPart("files-4", new File("testImages/5.png"))
                .formParams("txn_id", transactionId)
                .when()
                .post(TRANSACTION_BASEPATH + POST_ATTACHMENT)
                .then()
                .spec(responseSpecification);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66672780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档