FormData

Creates a multipart/form-data object that is suitable for file uploads and other kinds of POST.

It has a set of names and values of mime components. Names can be repeated. They will be presented in the same order in which you add them. You will mostly want to use the append method.

You can pass this directly to HttpClient.request.

Based on: https://developer.mozilla.org/en-US/docs/Web/API/FormData

auto fd = new FormData();
// add some data, plain string first
fd.append("name", "Adam");
// then a file
fd.append("photo", std.file.read("adam.jpg"), "image/jpeg", "adam.jpg");

// post it!
auto client = new HttpClient();
client.request(Uri("http://example.com/people"), fd).waitForCompletion();

Members

Functions

append
void append(string key, const(void)[] value, string contentType, string filename)

Appends the given entry to the request. This can be a simple key/value pair of strings or file uploads.

contentType
string contentType()

Gets the content type header that should be set in the request. This includes the type and boundary that is applicable to the toBytes method.

deleteKey
void deleteKey(string key)

Deletes any entries from the set with the given key.

entries
MimePart[] entries()

Returns all the current entries in the object.

get
MimePart get(string key)

Returns the first entry with the given key, or MimePart.init if there is nothing.

getAll
MimePart[] getAll(string key)

Returns the all entries with the given key.

has
bool has(string key)

Returns true if the given key exists in the set.

set
void set(string key, const(void)[] value, string contentType, string filename)

Sets the given key to the given value if it exists, or appends it if it doesn't.

toBytes
ubyte[] toBytes()

Returns bytes applicable for the body of this request. Use the contentType method to get the appropriate content type header with the right boundary.

Meta

History

Added June 8, 2018