Hey awesome directus team!
I need this one #1757 continued.
More than a year later, I have the same problem in just getting the image id from a "file" field but need the url instead.
See #1757
Get related image data like URL
Get image id
I tried the ?fields=*,header_image=* where "header_image" is my named "file" field. The output is only nesting the id like header_image":{"id":4}}. I tried with another field called tag, a relational field to another list collection and the nesting data is correct.
The whole is requested from a public state, no access token.
https://domain.tld/subfolder/apifolder/public/_/files/4 in browser get {"error":{"code":203,"message":"Item not found"}},
https://domain.tld/subfolder/apifolder/public/_/files responses with {"error":{"code":300,"message":"Reading items from \"directus_files\" collection was denied"}}.
That is ok, no public should enter my files.
But I need the url from the related image in the collection like https://domain.tld/subfolder/apifolder/public/uploads/_/originals/related_image.jpg.
That source is accessible from public browser.
Keep on rocking,
Matthias
I think you're using the fields param incorrectly (I'm no expert though). To keep things simple, just try this first: ?fields=*.*.*
That should get _all_ data three-levels deep. If that works then you can go to two-levels and then try to fetch the specific field.
I'm certain that this works and you have a malformed query string, so I'll close this. If this really is a bug then we can re-open and resolve!
Like @benhaynes said, ?fields=*,header_image=* is invalid. Try ?fields=*,header_image.* instead.
I just had the same thing - turned out it was an issue with the permissions. I had to grant read permissions to the directus_files table (Settings -> User Roles -> Public, then "Show Directus System Collections" -> tick the "read" checkbox next to the "Files" table).
Thanks for sharing this @tsixd
Just found my self on the same situation!
I just had the same thing - turned out it was an issue with the permissions. I had to grant read permissions to the directus_files table (Settings -> User Roles -> Public, then "Show Directus System Collections" -> tick the "read" checkbox next to the "Files" table).
this just happened to me but I can't fix it with your method, any suggestion?
I am also trying to understand how to display nested images information through the items API.
Tried everything that's been mentioned above but only ID is being returned.
Can we please have a quick tutorial of how to do this properly?
edit: never-mind, it works now. There must have been a small cache on the browser side.
@gianniskarmas — did you try the fields param? Something like ?fields=*.*.*
@benhaynes yes, thank you. It works and it was a small nginx caching problem.
While we are in the subject how to return only the url from images?
https://api2.konpoli.eu/public/_/items/products?fields=*,image.data.url
doesn't work as in example and if i try like ?fields=*.*,image.thumbnails.* it returns as invalid.
I can live with that but just trying to understand the logic behind deep querying with directus.
We'd need to see/know your data model to understand if that param is correct... but assuming you're following the Docs, that _looks_ correct. If you think it's a bug you can open a ticket (ideally with a database dump provided) and we'll get it fixed! If the DB is private you can share over our Slack too:
I just had the same thing - turned out it was an issue with the permissions. I had to grant read permissions to the directus_files table (Settings -> User Roles -> Public, then "Show Directus System Collections" -> tick the "read" checkbox next to the "Files" table).
I think the docs are quite bad. Maybe the directus team can add this to the "files & thumbnails" section. A Hint would be great
Most helpful comment
I just had the same thing - turned out it was an issue with the permissions. I had to grant read permissions to the directus_files table (Settings -> User Roles -> Public, then "Show Directus System Collections" -> tick the "read" checkbox next to the "Files" table).