Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't resolve file attachment URIs in log JSON #41

Open
richardostler opened this issue Dec 8, 2020 · 2 comments
Open

Can't resolve file attachment URIs in log JSON #41

richardostler opened this issue Dec 8, 2020 · 2 comments

Comments

@richardostler
Copy link

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

@mstenta
Copy link
Member

mstenta commented Dec 8, 2020

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.

@paul121
Copy link
Member

paul121 commented Feb 2, 2021

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

  • I think that this file field reference returns a path to the file entity (not a full URI) which can then be used to get the file in a separate request. But I'm unsure if the same Cookie Authentication applies... We'll need to look into this.

Some docs on creating files with Drupal 8/9 JSON:API: https://www.drupal.org/node/3024331

  • We might need to create some special methods to support this in farmOS.py. The headers & content type aren't JSON like all the other requests we make. Should be able to figure something out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants