httpMultipartPost static method

Future httpMultipartPost(
  1. Uri url,
  2. List<MultipartFile> files, {
  3. Map<String, dynamic>? body,
})

HTTP post method (multipart/form-data) url - request url (required) file - file to upload (required) body - parameters in map

Implementation

static Future<dynamic> httpMultipartPost(
    Uri url, List<http.MultipartFile> files,
    {Map<String, dynamic>? body}) async {
  body?.removeWhere(_nullFilter);
  var request = http.MultipartRequest('POST', url)
    ..headers.addAll({'Content-Type': 'multipart/form-data'})
    ..fields.addAll(body?.map((k, v) => MapEntry(k, '$v')) ?? {})
    ..files.addAll(files);
  return request
      .send()
      .then((response) => http.Response.fromStream(response))
      .then(_parseResponse)
      .catchError((error) => Future.error(error));
}