postMultipart method

Future postMultipart(
  1. String path, {
  2. Map<String, String>? fields,
  3. List<WtUpload>? files,
})

POST a multipart/form-data request (text fields + files).

Implementation

Future<dynamic> postMultipart(
  String path, {
  Map<String, String>? fields,
  List<WtUpload>? files,
}) async {
  final req = http.MultipartRequest('POST', _url(path));
  // multipart sets its own Content-Type boundary — drop the JSON one.
  final h = _headers()..remove('Content-Type');
  req.headers.addAll(h);
  if (fields != null) req.fields.addAll(fields);
  for (final f in files ?? const <WtUpload>[]) {
    req.files.add(http.MultipartFile.fromBytes(
      f.field,
      f.bytes,
      filename: f.filename,
      contentType: f.contentType != null ? MediaType.parse(f.contentType!) : null,
    ));
  }
  return _decode(await http.Response.fromStream(await req.send()));
}