upload method
Implementation
Future<List<FileInfo?>> upload(
List<XFile> files, {
Function(XFile file, int sent, int total)? onSent,
Function(XFile file, int code, String info)? onFail,
Function(FileInfo file)? onSucess,
}) async {
List<Future> fs = [];
List<FileInfo?> infos = [];
locate(XFile file) async {
var id = await fileManager.createFileId();
if (id == null) {
if (onFail != null) onFail(file, 1, "can't create file id");
return;
}
var info = await _upload(id, file, onSent, (err) {
if (onFail == null) {
if (kDebugMode) {
print(err);
}
}
if (err is DioException) {
if (err.response == null) {
onFail!(file, 2, err.message ?? "unkwon error");
return;
}
onFail!(file, err.response!.statusCode ?? 500,
err.response!.data ?? "unkown error");
return;
}
onFail!(file, 3, "$err");
});
if (info == null) {
return;
}
infos.add(info);
if (onSucess != null) {
onSucess(info);
}
}
for (var file in files) {
fs.add(locate(file));
}
await Future.wait(fs);
return infos;
}