Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert Niklasson 5 posts 75 karma points
    Apr 16, 2024 @ 09:30
    Robert Niklasson
    0

    Custom properties on media items missing in Content Delivery API response

    Hi! I'm setting up a brand new Umbraco 13 API with the Content Delivery API enabled. My issue is that images that are selected with the media picker on a document type only returns the default properties of that image . Any additional properties (Alt Text e.g.) I add to the Image media type are ignored.

    If I retrieve the image through the Media Delivery API then I do indeed get the custom properties, but I'd rather avoid doing extra calls to the API since I already have all the info except for a single property in the response from the CDA.

    Am I just fetching the data incorrectly? I've tried using the expand parameter but that didn't work. Or do I indeed have to make extra calls to the api to get the missing data?

    Umbraco version: 13.1.0

    Content Delivery API:

    {
      "focalPoint": null,
      "crops": [],
      "id": "182d28bd-1d00-44f9-84d4-b5ee73d8afb1",
      "name": "Istockphoto 636475496 612X612",
      "mediaType": "Image",
      "url": "/media/xmuc0gaa/istockphoto-636475496-612x612.jpg",
      "extension": "jpg",
      "width": 612,
      "height": 408,
      "bytes": 41030,
      "properties": {}
    }
    

    Media Delivery API:

    {
      "path": "/istockphoto 636475496 612x612/",
      "createDate": "2024-02-13T15:58:19.8894778",
      "updateDate": "2024-04-16T10:22:15.5563337",
      "id": "182d28bd-1d00-44f9-84d4-b5ee73d8afb1",
      "name": "Istockphoto 636475496 612X612",
      "mediaType": "Image",
      "url": "/media/xmuc0gaa/istockphoto-636475496-612x612.jpg",
      "extension": "jpg",
      "width": 612,
      "height": 408,
      "bytes": 41030,
      "properties": {
        "altText": "Adorable puppy being an extraordinarily good boy"
      },
      "focalPoint": null,
      "crops": []
    }
    
  • Studio Bravo 2 posts 72 karma points
    Apr 26, 2024 @ 00:46
    Studio Bravo
    0

    In our non-headless solutions we could access alt text via @image.UmbracoAlt, which would come through in the SSR request.

    For our headless solutions which leverage the Content Delivery API, we run into that same problem and alt text can't seem to be retrieved for an image in the same request as the content data. The properties key is just left blank.

    enter image description here

    It would be great if the alt text could be returned in the same call, but beyond making additional Media Delivery API requests, we aren't sure how.

  • Mateusz Kotwica 32 posts 133 karma points
    Nov 29, 2024 @ 13:31
    Mateusz Kotwica
    0

    Hey Robert,

    have you found a solution to your problem? I face exactly the same issue.

  • Robert Niklasson 5 posts 75 karma points
    Dec 10, 2024 @ 05:20
    Robert Niklasson
    0

    Hey Mateusz, I'm afraid I haven't found a solution to this yet. Hoping this feature will eventually get added to the Delivery API.

  • Studio Bravo 2 posts 72 karma points
    Dec 10, 2024 @ 03:44
    Studio Bravo
    0

    We also face the same problem and would like to avoid making a call to the Media API just to get ALT Text.

  • Mateusz Kotwica 32 posts 133 karma points
    Dec 11, 2024 @ 00:58
    Mateusz Kotwica
    0

    Well... I managed to do overcome this. I created my custom implementation of IApiMediaBuilder and IWebhookOutputExpansionStrategy and replaced the original services with them.

    Not really elegant but efficent :)

  • Stefan Zeilinger 2 posts 72 karma points
    Jan 14, 2025 @ 10:36
    Stefan Zeilinger
    0

    Matesuz Kowica, could you give us a code example of your implementation? We are currently facing the same problem with custom properties like alt-text.

  • Mateusz Kotwica 32 posts 133 karma points
    Jan 16, 2025 @ 13:12
    Mateusz Kotwica
    1

    I will not post the exact code as it is mainly copy-paste from the original Umbraco code, but I can guide you how I done it, so you will be able to recreate it easily on your own.

    And one disclaimer - I needed it for adjusting the webhook payload not API calls, but I believe the same code is used underneath to construct the result payload for both use cases, so I hope my workaround will also work for you :)

    So!

    After investigation it occurred that the root cause of the problem with missing custom media properties sits inside RequestContextOutputExpansionStrategyV2 class, especially I mean here the forceExpandProperties argument which is defaulted to false for content API.

    The first idea here was to create my own implementation for IOutputExpansionStrategy where I would add a support for extended properties coming from Media documents. Unfortunately I learned that for media properties the content serialization is called from ApiMediaBuilder and the reference is resolved using IOutputExpansionStrategyAccessor where I could not find any way how to overcome the logic to inject my own implementation of IOutputExpansionStrategy without messing with DI too much.

    That is why I decided to create my own implementation of, firstly, IOutputExpansionStrategy where I added support for extended properties, and secondly - for IApiMediaBuilder where I injected my custom IOutputExpansionStrategy implementation. The last step is just to swap the registration in the Di container during Umbraco startup.

    As mentioned earlier - it's not too elegant, but it works like a charm.

    I hope it helps!

  • nehakakar 20 posts 90 karma points
    Dec 31, 2024 @ 11:29
    nehakakar
    0

    I also faced this issue with the Content Delivery API not returning custom properties like Alt Text. It would be great if Umbraco could include these properties in the same call to avoid extra API requests. Hoping for a future update to address this

  • Stefan Zeilinger 2 posts 72 karma points
    30 days ago
    Stefan Zeilinger
    0

    I solved my problem now by trying property expansion again (Documentation: Property Expansion for Block Grid)

    My bad, that i didn't read the documentation properly the first time around ;)

    My expansion for a blockGrid Editor with some layouts and areas and different kinds of blocks, that might have image properties in them was: properties[contentBlockGrid[properties[$all]]]

    so in the call it is:

    ?expand=properties[contentBlockGrid[properties[$all]]]
    
Please Sign in or register to post replies

Write your reply to:

Draft