createCatalogImage method
Future<CatalogObject>
createCatalogImage({
- required CreateCatalogImageRequest request,
- String? authToken,
Uploads an image file to be represented by a CatalogImage object that can be linked to an existing CatalogObject instance.
The resulting CatalogImage is unattached to any CatalogObject if the object_id is not specified.
This CreateCatalogImage 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> createCatalogImage({
required CreateCatalogImageRequest request,
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");
//print (endpoint.toString());
var response = await
http.post(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());
}
}