Skip to content

Add function for downloading an uploaded file #628

Description

@timabbott

Zulip's API has a pair of related URLs for accessing uploaded files that need better documentation and tooling:

  • GET /user_uploads/...
  • GET /api/v1/user_uploads/...

The former just downloads a file (possibly via a 302 redirect to a temporary access URL of the form /user_uploads/temporary/...). The latter returns such a temporary access URL (basically what the former would have redirected to), which is useful for cases where a client's HTTP library doesn't support following redirects. Neither is currently covered in our API documentation.

The consequence of this is background is that client.call_endpoint() in the Python bindings using logic like this:

    path: str = re.fullmatch(
        '\s*cat\s*\[[^\[\]]*\]\(([^\(\)]*)\)\s*', message['content']
    ).group(1)

    content = str(client.call_endpoint(url = path, method = 'GET'))

which is the most convenient way to provide authentication, may end up visiting /api/v1/user_uploads and returning a temporary access URL, rather than downloading the file. What we need is an alternative to client.call_endpoint that doesn't prepend /api/v1/. One option would be to refactor the call_endpoint system to require passing /api/v1 explicitly, which might be a better system in any case; then something like the code above would work. (I'd want to provide an explicit client.fetch_upload(path | url) method in any case, but it could just call client.call_endpoint, and we'd have a clear mechanism for how to use API authentication to request other similar endpoints that don't have an /api/v1 prefix in the future -- which will largely be endpoints that serve images or other assets that need to be shared between web and mobile)

https://chat.zulip.org/#narrow/stream/49-development-help/topic/Bot.20download.20file/near/1027190 has more background

Activity

  1. ayushi19031 commented on Oct 10, 2020

    @ayushi19031
    Collaborator

    @zulipbot claim

  2. zulipbot commented on Oct 10, 2020

    @zulipbot
    Member

    Welcome to Zulip, @ayushi19031! We just sent you an invite to collaborate on this repository at https://github.com/zulip/python-zulip-api/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

    Here's some tips to get you off to a good start:

    As you work on this issue, you'll also want to refer to the Zulip code contribution guide, as well as the rest of the developer documentation on that site.

    See you on the other side (that is, the pull request side)!

  3. zulipbot commented on Oct 20, 2020

    @zulipbot
    Member

    Hello @ayushi19031, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

    You can reclaim this issue or claim any other issue by commenting @zulipbot claim on that issue.

    Thanks for your contributions, and hope to see you again soon!

  4. tushar912 commented on Jan 10, 2021

    @tushar912
    Member

    @zulipbot claim

  5. sundargs2000 commented on Feb 19, 2021

    @sundargs2000
    Collaborator

    @zulipbot claim

  6. zulipbot commented on Feb 19, 2021

    @zulipbot
    Member

    Welcome to Zulip, @sundargs2000! We just sent you an invite to collaborate on this repository at https://github.com/zulip/python-zulip-api/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

    Here's some tips to get you off to a good start:

    As you work on this issue, you'll also want to refer to the Zulip code contribution guide, as well as the rest of the developer documentation on that site.

    See you on the other side (that is, the pull request side)!

  7. 46 remaining items

  8. zulipbot commented on Oct 18, 2026

    @zulipbot
    Member

    @harshil0014 You can't claim this issue, as you're already working on 1 issue in this repository. Check out the contributing guide for advice on what to do while waiting for the next round of review.

  9. added a commit that references this issue on Oct 25, 2026
    a4e87a7
  10. tathyavarma commented on Oct 25, 2026

    @tathyavarma
    Collaborator

    @zulipbot claim

  11. zulipbot commented on Oct 25, 2026

    @zulipbot
    Member

    Welcome to Zulip, @tathyavarma! By picking up a Zulip issue, you're promising to do your best to follow Zulip's contributing guidelines. Neglecting to do so wastes maintainer time, and may result in being banned from contributing to Zulip.

    To get started:

    1. Work through all the "Prior to picking up your first issue" sections of the Zulip contributor guide.
    2. Post a comment here describing your plan for how to approach this issue. Before you claim an issue, you should be confident that you will be able to tackle it effectively.
    3. Accept the invite to collaborate on this repository at https://github.com/zulip/python-zulip-api/invitations. To avoid filling your inbox, we recommend unwatching this repository.

    The issue will be assigned to you when all three steps have been completed. If you get stuck, you can always @zulipbot abandon this issue, and pick a different one.

    If someone else claims this issue while you're working through the checklist, no worries! You can contribute by providing feedback on their pull request. If you’ve made good progress in understanding part of the codebase, you can also find another “help wanted” issue in the same area to work on.

  12. zulipbot commented on Nov 4, 2026

    @zulipbot
    Member

    @tathyavarma You have been unassigned from this issue because you have not made any updates for over 14 days. Please feel free to reclaim the issue if you decide to pick up again. Thanks!

  13. added a commit that references this issue on Nov 14, 2026
    3d3a649
  14. harshvardhan178251 commented on Nov 14, 2026

    @harshvardhan178251
    Collaborator

    Hi! I'd like to work on this. I read the server code (zproject/urls.py, zerver/views/upload.py) to pin down the behavior:

    • GET /api/v1/user_uploads/... returns a JSON temporary-access URL (serve_file_url_backend) - what call_endpoint() returns today, which is the bug in the issue.
    • The unprefixed GET /user_uploads/... path serves the file and supports API auth; the upload response's url is root-relative, so a download helper must resolve it against the server root and cannot reuse call_endpoint().

    Plan (non-breaking, no call_endpoint refactor): add Client.fetch_upload(url_or_path, timeout=None) that accepts an absolute URL or a server-root-relative /user_uploads/... path, GETs with the client session (redirects allowed), returns the raw bytes, and raises ZulipError on non-200. Unit tests with a mocked HTTP layer; happy to keep the call_endpoint prefix refactor out of this PR and discuss separately.

    @zulipbot claim

  15. zulipbot commented on Nov 14, 2026

    @zulipbot
    Member

    Welcome to Zulip, @harshvardhan178251! By picking up a Zulip issue, you're promising to do your best to follow Zulip's contributing guidelines. Neglecting to do so wastes maintainer time, and may result in being banned from contributing to Zulip.

    To get started:

    1. Work through all the "Prior to picking up your first issue" sections of the Zulip contributor guide.
    2. Post a comment here describing your plan for how to approach this issue. Before you claim an issue, you should be confident that you will be able to tackle it effectively.
    3. Accept the invite to collaborate on this repository at https://github.com/zulip/python-zulip-api/invitations. To avoid filling your inbox, we recommend unwatching this repository.

    The issue will be assigned to you when all three steps have been completed. If you get stuck, you can always @zulipbot abandon this issue, and pick a different one.

    If someone else claims this issue while you're working through the checklist, no worries! You can contribute by providing feedback on their pull request. If you’ve made good progress in understanding part of the codebase, you can also find another “help wanted” issue in the same area to work on.

  16. harshvardhan178251 commented on Nov 14, 2026

    @harshvardhan178251
    Collaborator

    Hi — a quick status check on this issue from my side. My PR #948 adds Client.fetch_upload() (returns raw file bytes; absolute off-server URLs rejected so bot credentials are not sent elsewhere). All checks pass except two upstream-dead CI jobs (the bullseye Zulip 4.0 job, and Python 3.9 on the current ubuntu-latest runner), both of which are fixed in #949. I'm happy to address any feedback on the PR.

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions