uploadFile method
upload file
Implementation
Future<Response> uploadFile({
required String path,
required String filePath,
bool isPost = true,
void Function(int received, int total)? sendProgress,
List<Map<String, String>>? body,
CancelToken? cancelToken,
}) async {
final File file = File(filePath);
final fileName = basename(file.path);
final FormData data = FormData.fromMap({
"file": await MultipartFile.fromFile(
file.path,
filename: fileName,
),
});
if (body != null) {
final x = body.map((e) => MapEntry(e.keys.first, e.values.first));
data.fields.addAll(x);
}
late Response response;
if (isPost) {
response = await _dio.post(path,
data: data, onSendProgress: sendProgress, cancelToken: cancelToken);
} else {
response = await _dio.patch(path,
data: data, onSendProgress: sendProgress, cancelToken: cancelToken);
}
_throwIfNoSuccess(response);
return response;
}