2017-06-09 17 views
1

我想使用Java和RestAssured庫上傳文件。有誰知道我可以如何使用這個庫上傳文件到一個字段?使用Restassured上傳文件

當使用郵遞員,我只是打電話給端點,並添加正文部分鍵=上傳和價值有一個「選擇文件」按鈕。

如何將文件上傳到使用Restassured的字段?我已經有一個使請求的主體和設置的所有參數吧,喜歡這裏的方法:

public CustomizationSetClientField(String clientId, String fieldSetName, String version, String fieldName, String name, String type, String value, String language, String role){ 
     this.body.put("name", name); 
     this.body.put("type", type); 
     this.body.put("value", value); 

     this.url = Config.getByName("customization_url"); 
     this.pathTemplate = Config.getByName("customization_set_client_field"); 
     this.path = Utils.createPath(pathTemplate, clientId, fieldSetName, version, fieldName); 
     this.role = role; 


    } 

現在,這是用於設置字段,但我不知道如何使用Restassured與上傳,可以請你告訴我如何?

回答

0

您可能在尋找multipart file uploads。例如:

given(). 
     multiPart("file", new File("/path/to/file")). 
when(). 
     post("/upload");