Open richardostler opened 3 years ago
Ah good question @richardostler - this might require some extra work/thought...
File uploads are "private" in farmOS - which means they are not accessible for visitors who are not "logged in" to access them.
"Logged in" in this case does not mean "authenticated via OAuth" - it means "authenticated with a session cookie". So unfortunately it may not be possible retrieve actual files via the API using OAuth authentication. It's possible to get the URI (as you found), but pulling the actual file content requires a session cookie.
Maybe it would be possible to override the access control logic for file paths such that it DOES work with OAuth authentication as well... but we probably won't add that to farmOS 1.x. It would need to be something added to the 2.x roadmap.
As far as farmOS 2.x & Drupal JSON:API goes...
An example of getting an entity with a file reference: https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/fetching-resources-get#s-get-article-media-entity-reference-field-image-url-uri-by-including-references
Some docs on creating files with Drupal 8/9 JSON:API: https://www.drupal.org/node/3024331
Hiya,
For logs that have file attachments I want to be able to resolve the provided URI in the log JSON, but the URI gives a 404. Looking at log in FarmOS, the url for attached documents is in the format: https://my-farm.farmos.net/system/files/farm/log/harvest/_filename.ext_, rather the JSON URI which is: https://my-farm.farmos.net/file/_ID_
cheers
Richard