uploadFiles method
Implementation
Future<Response> uploadFiles(
{required String path,
required List<DioUploadFileModel> filesModel,
void Function(int received, int total)? sendProgress,
List<Map<String, String>>? body,
CancelToken? cancelToken}) async {
final mapOfData = <String, dynamic>{};
for (final file in filesModel) {
final nextFile = File(file.filePath);
final fileName = basename(nextFile.path);
mapOfData.addAll({
file.fileFiledName: await MultipartFile.fromFile(
nextFile.path,
filename: fileName,
),
});
}
final formData = FormData.fromMap(mapOfData);
if (body != null) {
final x = body.map((e) => MapEntry(e.keys.first, e.values.first));
formData.fields.addAll(x);
}
final Response response = await _dio.post(path,
data: formData, onSendProgress: sendProgress, cancelToken: cancelToken);
_throwIfNoSuccess(response);
return response;
}