updateCatalogImage method
Future<CatalogObject>
updateCatalogImage({
- required UpdateCatalogImageRequest request,
- required String imageId,
- String? authToken,
Uploads a new image file to replace the existing one in the specified CatalogImage object.
This UpdateCatalogImage endpoint accepts HTTP multipart/form-data requests with a JSON part and an image file part in JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB.
Implementation
Future<CatalogObject> updateCatalogImage({
required UpdateCatalogImageRequest request,
required String imageId,
String? authToken,
}) async {
authToken ??= authenticationService.getCachedToken()?.accessToken;
Map<String, String> headers = {
"Authorization": "Bearer ${authToken ?? ""}",
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
};
Uri endpoint = Uri.https(
baseUrl, "/v2/catalog/images/$imageId");
//print (endpoint.toString());
var response = await
http.put(endpoint, body: jsonEncode(request), headers: headers);
if (response.statusCode == 200) {
print (jsonDecode(response.body));
return CatalogResponse.fromJson(jsonDecode(response.body)).image!;
}
else {
print (response.body);
throw CatalogException(statusCode: response.statusCode, message: CatalogResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
}
}