Here is what documentation contains with an example:
A multipart/form-data request.
Such a request has both string fields, which function as normal
form fields, and (potentially streamed) binary files.
This request automatically sets the Content-Type header to
multipart/form-data. This value will override any value set by the
user.
var uri = Uri.parse('https://example.com/create');
var request = http.MultipartRequest('POST', uri) // your uri / url (encoded)
..fields['user'] = '[email protected]' // your fields key - value
..files.add(await http.MultipartFile.fromPath(
'package', 'build/package.tar.gz',
contentType: MediaType('application', 'x-tar'))); // your file(s)
var response = await request.send();
if (response.statusCode == 200) print('Uploaded!'); // what should be done when success
Note that there is a pacakge powerful Http client for Dart/Flutter
called dio which support File download and FormData.
Here is its documentation example:
Sending FormData:
FormData formData = new FormData.fromMap({
"name": "wendux",
"age": 25,
"file": new UploadFileInfo(new File("yourfile.extension"), "filename.extension") // if you a file is type of file then no need to create File()
});
response = await dio.post("/info", data: formData);