Skip to content

[PUI] How to download attachments and reports #5697

Closed

Description

@SchrodingersGat

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?

Activity

  1. added
    question
    User Interface
    on Oct 15, 2023
  2. added this to the 0.13.0 milestone on Oct 15, 2023
  3. wolflu05 commented on Oct 15, 2023

    @wolflu05
    Member

    Also related #5531

  4. added
    help wanted
    roadmap
    and removed
    roadmap
    on Oct 15, 2023
  5. matmair commented on Oct 16, 2023

    @matmair
    Member

    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?

  6. SchrodingersGat commented on Oct 16, 2023

    @SchrodingersGat
    MemberAuthor

    @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
  7. SchrodingersGat commented on Oct 16, 2023

    @SchrodingersGat
    MemberAuthor

    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

  8. matmair commented on Oct 16, 2023

    @matmair
    Member

    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.

  9. SchrodingersGat commented on Oct 16, 2023

    @SchrodingersGat
    MemberAuthor

    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

  10. matmair commented on Oct 16, 2023

    @matmair
    Member

    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

  11. modified the milestones: 0.13.0, 1.0.0 on Oct 17, 2023
  12. changed the title [-][React] How to download attachments and reports[/-] [+][PUI] How to download attachments and reports[/+] on Oct 18, 2023
  13. moved this from Todo to In Review in User Interface Redesignon Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    User Interfacehelp wantedquestion

    Type

    No type

    Projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions