uploadBytes method
upload file bytes
Implementation
Future<Response> uploadBytes(
{required String path,
required Uint8List bytes,
void Function(int received, int total)? sendProgress,
List<Map<String, String>>? body,
bool isPost = true,
required String bytesExtension,
bool loading = false,
CancelToken? cancelToken}) async {
try {
final FormData data = FormData.fromMap({
"file": MultipartFile.fromBytes(bytes,
filename:
"${DateTime.now().microsecondsSinceEpoch}.$bytesExtension"),
});
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;
} catch (err) {
rethrow;
}
}