handleMultipart method
Implementation
Future<http.StreamedResponse> handleMultipart(ApiRequest request) {
var uri = _buildUri(request);
http.MultipartRequest req = http.MultipartRequest(
request.method ?? ApiMethods.get,
uri,
);
request.body?.forEach((key, value) async {
if (value is FileFormField) {
if (value.bytes != null) {
req.files.add(http.MultipartFile.fromBytes(key, value.bytes!,
filename: value.path));
} else if (value.stringFile != null) {
req.files.add(http.MultipartFile.fromString(key, value.stringFile!,
filename: value.path));
} else {
req.files.add(await http.MultipartFile.fromPath(key, value.path ?? '',
// filename: value.path?.split('/').last ?? '',
contentType:
MediaType.parse(lookupMimeType(value.path ?? '') ?? '')));
}
} else {
req.fields[key] = value.toString();
}
});
request.headers.forEach((key, value) {
req.headers[key] = value;
});
return req.send();
}