uploadNewImagesOrFiles<DataT extends Data> method
upload a bunch of images
Implementation
RequestAndParser<http.BaseResponse, String?>
uploadNewImagesOrFiles<DataT extends Data>(
DataT data,
List<XFile> files,
) {
debugPrint('uploading images ${files.map((e) => e.name)}');
var jsonData = data.toJson();
final rd = RequestData.fromFiles(
_uploadImage_r,
json: {
'type': Helper.getIdentifierFromData(data),
'data': json.encode(jsonData),
},
multipartFiles: files,
);
parser(http.BaseResponse res) async {
if (res.statusCode ~/ 100 != 2) {
debugPrint('image uploading not ok: ${res.statusCode.toString()}');
throw BackendCommunicationException(
'we need a 2xx, but got ${res.statusCode}');
}
return (res.runtimeType == http.Response)
? (res as http.Response?)?.body //meh
: await (res as http.StreamedResponse?)?.stream.bytesToString();
}
return RequestAndParser(rd: rd, parser: parser);
}