When sending larger amount of data to the server it’s common to use the multipart form data technique. Rest Assured provide methods called multiPart that allows you to specify a file, byte-array, input stream or text to upload. In its simplest form you can upload a file like this:
Option 1: File (.json , .txt) without control name (Default control name: file)
given().
multiPart(new File("/path/to/file")).
when().
post("/upload");
Option 2: File (.json , .txt) with Control name
given().
multiPart("controlName", new File("/path/to/file")).
when().
post("/upload");
Option 3: File (.pdf) with Control name
given().
multiPart("controlName", new File("/path/to/file"),"application/pdf").
when().
post("/upload");
Option 4 : json object with Control name
given().
multiPart("controlName", jsonObject,"application/json").
when().
post("/upload");
Option 5 : PDF file + json object with Control name
given().
multiPart("controlName", new File("/path/to/file"),"application/pdf").
multiPart("controlName", jsonObject,"application/json").
when().
post("/upload");
Nice and clean explaination, but lacks example for latest rfc7578 forms, like:
——WebKitFormBoundaryGAnAFaOOKFFAFJyc
Content-Disposition: form-data; name=”formField1″
formField1Value
——WebKitFormBoundaryGAnAFaOOKFFAFJyc
As you can see – it has no content type, no file, just pure data
LikeLike
Thanks for your Feedback. Good point, I will surely add such examples and few more soon.
I Appreciate it your effort in sharing feedback.
LikeLike