Skip to content

FormData ​

Added in: v1.18

The FormData is used create form data that is sent via APIRequestContext.

Methods ​

FormData.Append() ​

Added in: v1.44

Appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist. File values can be passed either as Path or as FilePayload. Multiple fields with the same name can be added.

The difference between FormData.Set() and FormData.Append() is that if the specified key already exists, FormData.Set() will overwrite all existing values with the new one, whereas FormData.Append() will append the new value onto the end of the existing set of values.

csharp
var multipart = Context.APIRequest.CreateFormData();
// Only name and value are set.
multipart.Append("firstName", "John");
// Name, value, filename and Content-Type are set.
multipart.Append("attachment", new FilePayload()
{
    Name = "pic.jpg",
    MimeType = "image/jpeg",
    Buffer = File.ReadAllBytes("john.jpg")
});
// Name, value, filename and Content-Type are set.
multipart.Append("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 });

Arguments

  • name string

    Field name.

  • value string | boolean | int | Object

    Field value.

    • name string

      File name

    • mimeType string

      File type

    • buffer Buffer

      File content

Returns

  • FormData

FormData.Set() ​

Added in: v1.18

Sets a field on the form. File values can be passed either as Path or as FilePayload.

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")
});
multipart.Set("age", 30);
await Page.APIRequest.PostAsync("https://localhost/submit", new() { Multipart = multipart });

Arguments

  • name string

    Field name.

  • value string | boolean | int | Object

    Field value.

    • name string

      File name

    • mimeType string

      File type

    • buffer Buffer

      File content

Returns

  • FormData

Released under the Apache 2.0 License.