uploadImage method
Build and execute a image upload to bagelDB, for a specific item in a collection. image
should be a valid file object and slug
is the field to which the image will be updated. The item() methods must have been used in order to execute uploadImage
Implementation
Future<BagelResponse> uploadImage(String slug, File image) async {
String fileName = image.path.split('/').last;
FormData formData = FormData.fromMap({
"imageFile": await MultipartFile.fromFile(
image.path,
filename: fileName,
),
});
String url =
'$baseEndpoint/collection/$collectionID/items/$_item/image?imageSlug=$slug';
if (nestedCollectionsIDs.isNotEmpty) {
String nestedID = nestedCollectionsIDs.join(".");
url = '$url&nestedID=$nestedID';
}
Dio dio = await _dio();
Response res = await dio.put(url, data: formData);
return BagelResponse(data: res.data, statusCode: res.statusCode!);
}