diff --git a/docs/src/api/class-formdata.md b/docs/src/api/class-formdata.md index 8a77f73c47..76a1f85619 100644 --- a/docs/src/api/class-formdata.md +++ b/docs/src/api/class-formdata.md @@ -14,6 +14,72 @@ FormData form = FormData.create() page.request().post("http://localhost/submit", RequestOptions.create().setForm(form)); ``` +## method: FormData.add +* since: v1.43 +- returns: <[FormData]> + +Adds a field to the form. File values can be passed either as `Path` or as `FilePayload`. +Multiple fields with the same name can be added. + +```java +import com.microsoft.playwright.options.FormData; +... +FormData form = FormData.create() + // Only name and value are set. + .add("firstName", "John") + // Name and value are set, filename and Content-Type are inferred from the file path. + .add("attachment", Paths.get("pic.jpg")) + // Name, value, filename and Content-Type are set. + .add("attachment", new FilePayload("table.csv", "text/csv", Files.readAllBytes(Paths.get("my-tble.csv")))); +page.request().post("http://localhost/submit", RequestOptions.create().setForm(form)); +``` + +```csharp +var multipart = Context.APIRequest.CreateFormData(); +// Only name and value are set. +multipart.Add("firstName", "John"); +// Name, value, filename and Content-Type are set. +multipart.Add("attachment", new FilePayload() +{ + Name = "pic.jpg", + MimeType = "image/jpeg", + Buffer = File.ReadAllBytes("john.jpg") +}); +// Name, value, filename and Content-Type are set. +multipart.Add("attachment", new FilePayload() +{ + Name = "table.csv", + MimeType = "text/csv", + Buffer = File.ReadAllBytes("my-tble.csv") +}); +await Page.APIRequest.PostAsync("https://localhost/submit", new() { Multipart = multipart }); +``` + +### param: FormData.add.name +* since: v1.43 +- `name` <[string]> + +Field name. + +### param: FormData.add.value +* since: v1.43 +- `value` <[string]|[boolean]|[int]|[Path]|[Object]> + - `name` <[string]> File name + - `mimeType` <[string]> File type + - `buffer` <[Buffer]> File content + +Field value. + +### param: FormData.add.value +* since: v1.43 +* langs: csharp +- `value` <[string]|[boolean]|[int]|[Object]> + - `name` <[string]> File name + - `mimeType` <[string]> File type + - `buffer` <[Buffer]> File content + +Field value. + ## method: FormData.create * since: v1.18 * langs: java @@ -80,69 +146,3 @@ Field value. - `buffer` <[Buffer]> File content Field value. - -## method: FormData.add -* since: v1.43 -- returns: <[FormData]> - -Adds a field to the form. File values can be passed either as `Path` or as `FilePayload`. -Multiple fields with the same name can be added. - -```java -import com.microsoft.playwright.options.FormData; -... -FormData form = FormData.create() - // Only name and value are set. - .add("firstName", "John") - // Name and value are set, filename and Content-Type are inferred from the file path. - .add("attachment", Paths.get("pic.jpg")) - // Name, value, filename and Content-Type are set. - .add("attachment", new FilePayload("table.csv", "text/csv", Files.readAllBytes(Paths.get("my-tble.csv")))); -page.request().post("http://localhost/submit", RequestOptions.create().setForm(form)); -``` - -```csharp -var multipart = Context.APIRequest.CreateFormData(); -// Only name and value are set. -multipart.Add("firstName", "John"); -// Name, value, filename and Content-Type are set. -multipart.Add("attachment", new FilePayload() -{ - Name = "pic.jpg", - MimeType = "image/jpeg", - Buffer = File.ReadAllBytes("john.jpg") -}); -// Name, value, filename and Content-Type are set. -multipart.Add("attachment", new FilePayload() -{ - Name = "table.csv", - MimeType = "text/csv", - Buffer = File.ReadAllBytes("my-tble.csv") -}); -await Page.APIRequest.PostAsync("https://localhost/submit", new() { Multipart = multipart }); -``` - -### param: FormData.add.name -* since: v1.43 -- `name` <[string]> - -Field name. - -### param: FormData.add.value -* since: v1.43 -- `value` <[string]|[boolean]|[int]|[Path]|[Object]> - - `name` <[string]> File name - - `mimeType` <[string]> File type - - `buffer` <[Buffer]> File content - -Field value. - -### param: FormData.add.value -* since: v1.43 -* langs: csharp -- `value` <[string]|[boolean]|[int]|[Object]> - - `name` <[string]> File name - - `mimeType` <[string]> File type - - `buffer` <[Buffer]> File content - -Field value.