From c5097a500d68edfc7439d8efe6276ac2a944ff3f Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 11 Jan 2024 18:36:05 +0100 Subject: [PATCH] docs: add java/csharp code snippets for FormData (#28951) Fixes https://github.com/microsoft/playwright/issues/28811 --------- Signed-off-by: Max Schmitt Co-authored-by: Dmitry Gozman --- docs/src/api/class-formdata.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/src/api/class-formdata.md b/docs/src/api/class-formdata.md index 2d9efd17d6c7e..c578021653b28 100644 --- a/docs/src/api/class-formdata.md +++ b/docs/src/api/class-formdata.md @@ -27,6 +27,34 @@ Creates new instance of [FormData]. Sets a field on the form. File values can be passed either as `Path` or as `FilePayload`. +```java +import com.microsoft.playwright.options.FormData; +... +FormData form = FormData.create() + // Only name and value are set. + .set("firstName", "John") + // Name and value are set, filename and Content-Type are inferred from the file path. + .set("profilePicture1", Paths.get("john.jpg")) + // Name, value, filename and Content-Type are set. + .set("profilePicture2", new FilePayload("john.jpg", "image/jpeg", Files.readAllBytes(Paths.get("john.jpg")))); + .set("age", 30); +page.request().post("http://localhost/submit", RequestOptions.create().setForm(form)); +``` + +```csharp +var multipart = Context.APIRequest.CreateFormData(); +// Only name and value are set. +multipart.Set("firstName", "John"); +// Name, value, filename and Content-Type are set. +multipart.Set("profilePicture", new FilePayload() +{ + Name = "john.jpg", + MimeType = "image/jpeg", + Buffer = File.ReadAllBytes("john.jpg") +}); +await Page.APIRequest.PostAsync("https://localhost/submit", new() { Multipart = multipart }); +``` + ### param: FormData.set.name * since: v1.18 - `name` <[string]>