FormData
The FormData is used create form data that is sent via APIRequestContext.
Methods
Append
Added in: v1.44Appends 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.
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 });
Usage
FormData.Append(name, value);
Arguments
Returns
Set
Added in: v1.18Sets a field on the form. File values can be passed either as Path
or as FilePayload
.
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 });
Usage
FormData.Set(name, value);
Arguments
Returns