Get assets "description"-value on images

Hi,

is there a way to get the value of the assets field “description” (when editing asset) in the response data? If I set a collection fields type to “asset” I get this property. If I set a fields type to “gallery” or “image” I only get the “meta” - values “title” and “asset”(id). I guess I could do new request for all those asset-ids but I am looking for a cleaner solution.

Thank you

@rohagihu, did you ever figure this out? I’ve got the same question. :thinking:

@Mr_JimWest unfortunately not. I’ve used field type “set” as workaround for composing image+text.

I assume you are referring to the empty description key in the assets data object when you retrieve an entry which has a “linked” asset.

The problem seems to be the way assets are linked/stored with a collection entry.

Once you select an asset its data object is not simply linked but stored with the collection entry.

Once you edit the linked asset (and therefore change its data object), those changes are not copied over to the collection entry.

You have to go “asset > replace > select-once-more-the-same-asset > save” and only then the updated description is suddenly showing when querying the entry.

Not sure how this feature/bug is to be treated. But these are the technicalities around this problem.

A “fix” would be

  1. on updating an asset to update all entries that “somehow” have the respective asset linked to them
    - or -
  2. to repopulate asset fields on “retrieve” with the latest info from the assets collection (instead of relying on a possibly outdated “local copy” of the assets data object).

(2) could be implemented by yourself in a “GET” rule script. As a local fix for your collections asset fields.

@rohagihu, thanks for the reply.

@abernh, the issue is not that we are getting bad/outdated data, it’s that the collection’s JSON does not output the ‘description’ for ‘image’ field types in the first place. As soon as we change the image field to an ‘asset’ field type, it works as expected.

Is it possible to change what does and does not show in the JSON?

@abernh, as you mentioned…now that I take a look at at the asset field type; sure enough, it’s not updating the content either. And as you suggested, selecting “Replace”, and selecting the same file again does the trick. Thanks for the insight. :+1:

I made some tests with an image field and I don’t see any issues. All the meta information that I add is correctly saved and also returned by the API.

These are my image field params:

{
  "meta": {
    "title": {
      "type": "text",
      "label": "Title"
    },
    "description": {
      "type": "text",
      "label": "Description"
    }
  }
}

and this is what the API returns

   {
      "_id": "6123b44c6138326b83000331",
      ...
      "image1": {
        "path": "Sometestimage.png",
        "meta": {
          "title": "meta title",
          "description": "meta description"
        }
      }
    },

This does appear to work; but it does not connect the metadata already on the image itself.

If I upload an image to a folder in the assets ‘library’, add a title and description, and add that image to the image field-type on three different collection entries, the previously added title and description does not get passed through to the entry or the JSON; and with your method, would have to be added three times; one to each page. Changing the “image” field type to “asset” solves this; the default metadata shows up in the JSON as expected.

My current projects is going to be dealing with lots of photography. I initially thought making a collection of just the photos; and the needed metadata, would work, but then I realized that their is no way to really preview the photos in the collection. Clicking each little photo icon, or having an extremely detailed title/description does not sound fun. But, if the metadata that’s pulled through isn’t updated when the asset’s metadata is updated, I may need to go this route…I suppose I could just use that image ID and do a separate request for each image. :laughing:

I appreciate your guidance @abernh

The described functionality for the image type sounds to me that it works as expected.
If you save an asset only as an image, then this is a single instance of this asset and the added information about title, details etc are only meta information related to each specific image instance.

Yes, this would have been my next thought as well and the resulting bad UX is an unexpected downside to it.
To fix that shortcoming you would have to extend the form view.

But those are then your 2 options

  • going for your “custom asset collection” and fixing the bad UX
  • or using the original asset field type and fixing the sync

I’d say the latter might be less work (“data-transforming” seems easier than UI adjusting).