2017-01-28 37 views
0

我有一個職位的API調用,它允許我在表單數據參數名爲「文件」 上傳多個圖像我可以發送多個文件的表單數據有關鍵「文件」和值作爲多個文件多文件上傳與休息放心

我想模擬與休養生息的Java客戶端相同的調用。我可以上傳單個文件,但不能上傳多個文件。

以下爲單文件上傳休息,保證代碼:

File sheetFile = new File(sheetPath.get(0)); 
response = RestAssured. 
      given(). 
       headers(headers). 
       formParameter("studentDetail", 
         "{"+ 
         "\"userId\" : "+PropFileHandler.readProperty("psUserId")+ 
         ",\"institutionId\" : "+PropFileHandler.readProperty("institution_id")+ 
         ",\"externalUserId\" : "+PropFileHandler.readProperty("user_id")+ 
         ",\"tokenId\" : \"12000\""+ 
         ",\"imagePathStatus\" : \"\""+ 
         "}"). 
       formParameter("clientType", getData("ps_bulk_upload_image.clientType")). 
       multiPart("file", sheetFile). #here i want to upload multile files 
      when(). 
       post(relativePath). 
      then(). 
       statusCode(200). 
       body(matchesJsonSchema(new File(test.cngActions.getJsonSchemaDirectoryPath()+ 
         getData("ps_bulk_upload_image.schemaPath")))). 
       extract().response(); 

任何幫助,將不勝感激。

回答

0

只需撥打multiPart多次。

在這裏看到:https://blog.jayway.com/2011/09/15/multipart-form-data-file-uploading-made-simple-with-rest-assured/

相關代碼:

given(). 
    multiPart("file1", new File("/home/johan/some_large_file.bin")). 
    multiPart("file2", new File("/home/johan/some_other_large_file.bin")). 
    multiPart("file3", "file_name.bin", inputStream). 
    formParam("name", "value"). 
expect(). 
    body("fileUploadResult", is("OK")). 
when(). 
    post("/advancedFileUpload");