Directus: Get row with "Single File" field by API only returns the file id instead of file data, Part 2

Created on 31 Jan 2019  Â·  10Comments  Â·  Source: directus/directus

Bug Report

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.

Steps to Reproduce

See #1757

Expected Behavior

Get related image data like URL

Actual Behavior

Get image id

Other Context & Screenshots

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.

Technical Details

  • Device: [Desktop]
  • OS: [Linux Shared Hosted Server]
  • Web Server: [Apache]
  • PHP Version: [7.3]
  • Database: [MySQL 8.?]
  • Install Method: [manual setup release v.7.0.16]

Keep on rocking,
Matthias

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).

All 10 comments

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=*.*.*

https://docs.directus.io/api/reference.html#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:

https://directus.chat

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pvshum picture pvshum  Â·  4Comments

asitemade4u picture asitemade4u  Â·  3Comments

benhaynes picture benhaynes  Â·  4Comments

lluishi93 picture lluishi93  Â·  3Comments

dimitrov-adrian picture dimitrov-adrian  Â·  3Comments