multipartRequest method
Future
multipartRequest(
- dynamic method,
- dynamic url,
- dynamic payload,
- dynamic headers,
- dynamic files,
Implementation
Future<dynamic> multipartRequest(method, url, payload, headers, files) async {
final request = http.MultipartRequest(method, url);
headers["Content-Type"] = "multipart/form-data";
request.headers.addAll(headers);
request.fields.addAll(Map<String, String>.from(payload));
if (files != null) {
for (dynamic file in files) {
request.files.add(await http.MultipartFile.fromPath(
file['array_key'],
file['file'].path,
contentType: MediaType("image", p.extension(file['file'].path)),
));
}
}
dynamic streamedResponse = await request.send();
return await http.Response.fromStream(streamedResponse);
}