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

[PUI] How to download attachments and reports #5697

Closed
SchrodingersGat opened this issue Oct 15, 2023 · 7 comments · Fixed by #6970
Closed

[PUI] How to download attachments and reports #5697

SchrodingersGat opened this issue Oct 15, 2023 · 7 comments · Fixed by #6970
Labels
help wanted Assistance required question This is a question User Interface Related to the frontend / User Interface
Milestone

Comments

@SchrodingersGat
Copy link
Member

SchrodingersGat commented Oct 15, 2023

Related issues:

The new user interface will be driven entirely by the API. Thus, downloading files (like attachments, reports, etc) no longer relies on session cookies.

so, how do we provide "file download" for the user? Note that any media files served / hosted by InvenTree require user authentication (e.g. via auth token).

So, we need a way to fetch the file and present to the user for download, via the web client.

Many of the ways I have found are very clunky, requiring first downloading the file to browser RAM, and then making a hidden button and "clicking" the button (in software). Or, similar tricks using hidden web forms.

Surely there is a better way? Any suggestions how we can cleanly do this via the API, without any of these hacks tricks?

@SchrodingersGat SchrodingersGat added question This is a question User Interface Related to the frontend / User Interface labels Oct 15, 2023
@SchrodingersGat SchrodingersGat added this to the 0.13.0 milestone Oct 15, 2023
@wolflu05
Copy link
Contributor

Also related #5531

@SchrodingersGat SchrodingersGat added help wanted Assistance required roadmap This is a roadmap feature with no immediate plans for implementation and removed roadmap This is a roadmap feature with no immediate plans for implementation labels Oct 15, 2023
@matmair
Copy link
Member

matmair commented Oct 16, 2023

I do not really see why it is not working with basic links; I will investigate tonight.
If required I think we should change the backend for this so we can just link to a download endpoint instead of having to work around in the frontend with it.
Maybe this is a solution?

@SchrodingersGat
Copy link
Member Author

@matmair as far as I can tell, it is because the browser does not have a session cookie. Have a look at the request headers when you download a file in the current UI, vs the react UI.

Here is the request to do a "simple download" of the file in the new UI, which only has login via token auth - no browser session auth:

Screenshot 2023-10-16 at 7 11 25 pm

This is the same reason that I have been working on this PR for images

One option I have considered:

  1. At login, request a "session cookie" from the server
  2. Save the cookie to the session
  3. Any "media file links" can then be downloaded without any extra issues

@SchrodingersGat
Copy link
Member Author

If required I think we should change the backend for this so we can just link to a download endpoint instead of having to work around in the frontend with it.

I would prefer this too - the required changes to the frontend would be prohibitive

@matmair
Copy link
Member

matmair commented Oct 16, 2023

I think adding a session token should be a (somewhat) easy feat. I got images working in #5545 without it but touching this up will be necessary for reports anyway.

@SchrodingersGat
Copy link
Member Author

I think adding a session token should be a (somewhat) easy feat.

I hope so! I have not yet found any good examples of this

@matmair
Copy link
Member

matmair commented Oct 16, 2023

I have done something similar in the past - we need to argument the token endpoint to instantiate a session/log the user in and set the session token in the response. I will tackle it once #5582 is done; that is getting to the finishing line

@SchrodingersGat SchrodingersGat modified the milestones: 0.13.0, 1.0.0 Oct 17, 2023
@matmair matmair changed the title [React] How to download attachments and reports [PUI] How to download attachments and reports Oct 18, 2023
SchrodingersGat added a commit to SchrodingersGat/InvenTree that referenced this issue Feb 1, 2024
- Part of inventree#5697
- Cherry picking just the API fixes
SchrodingersGat added a commit that referenced this issue Feb 1, 2024
- Part of #5697
- Cherry picking just the API fixes
@matmair matmair moved this from Todo to In Review in User Interface Redesign Mar 20, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in User Interface Redesign Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Assistance required question This is a question User Interface Related to the frontend / User Interface
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants