retrieve images with global crop values
# help-with-umbraco
a
I would like to use images through delivery Api with global crops. When I use ImageBlock with imageMedia property it returns with global crop id, alias, width, height and coordinates but when I use imageContent type with image property (both with image mediaType) it returns only local crops with values and global crops are returned with $ref reference value. - How can I return here global crop values instead of $ref value? - How can I use $ref for querying and displaying an image with global crop? I see that local and global crops are different as local image crop data is stored on the document in this property from Global crops as they are defined on the Media Item, making the crops shared between all usage of that Media Item. But how can we query / return the global crop data with Delivery Api or custom Api? Thanks, Attila
What I can see that this can be because of Json Serializer setting: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/preserve-references services.AddControllers().AddJsonOptions(Constants.JsonOptionsNames.DeliveryApi, options => { // Ignore MaxDepth options.JsonSerializerOptions.MaxDepth = 0; options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve; options.JsonSerializerOptions.Converters.Add(new CustomJsonConverterForType()); options.JsonSerializerOptions.TypeInfoResolver = new FallbackDeliveryApiJsonTypeResolver(); }); We configured the following to fix the following exception: System.Text.Json.JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles. Path: $.Properties.Items.Areas.Items.Content.Properties.ContentType.PropertyTypes.ContentType.PropertyTypes.ContentType.PropertyTypes.ContentType.PropertyTypes.ContentType.PropertyTypes.ContentType.PropertyTypes.ContentType.Key. at System.Text.Json.ThrowHelper.ThrowJsonException_SerializerCycleDetected(Int32 maxDepth)
16 Views