python-zulip-api icon indicating copy to clipboard operation
python-zulip-api copied to clipboard

Add function for downloading an uploaded file

Open timabbott opened this issue 3 years ago • 25 comments

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

timabbott avatar Oct 01 '20 18:10 timabbott

@zulipbot claim

ayushi19031 avatar Oct 10 '20 16:10 ayushi19031

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)!

zulipbot avatar Oct 10 '20 16:10 zulipbot

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!

zulipbot avatar Oct 20 '20 18:10 zulipbot

@zulipbot claim

tushar912 avatar Jan 10 '21 09:01 tushar912

@zulipbot claim

sundargs2000 avatar Feb 19 '21 19:02 sundargs2000

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)!

zulipbot avatar Feb 19 '21 19:02 zulipbot

Hey, I would like to work on this. So, the tasks involved would be -

  1. Refactor the code to add another parameter to the call_endpoint function to specify the API version (with default being v1).
  2. Create another function fetch_upload to download an uploaded file which takes a url parameter and another path parameter to which it writes the file.

I was thinking the parameter could be a string called api_version, which we can check if it is valid, else use default as v1. For nothing to be prepended, they need to explicitly pass None or an empty string. Please let me know if this sounds right so I can get started on working on this.

sundargs2000 avatar Feb 24 '21 18:02 sundargs2000

@aditisinghchauhan 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!

zulipbot avatar Mar 07 '21 01:03 zulipbot

@zulipbot claim

yasiruRathnayaka97 avatar Mar 21 '21 19:03 yasiruRathnayaka97

Welcome to Zulip, @yasiruRathnayaka97! 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)!

zulipbot avatar Mar 21 '21 19:03 zulipbot

@zulipbot claim

Ponni-M avatar Apr 18 '21 12:04 Ponni-M

Hello @Ponni-M, it looks like we've already sent you a collaboration invite at https://github.com/zulip/python-zulip-api/invitations, but you haven't accepted it yet!

Please accept the invite and try to claim this issue again afterwards. We look forward to your contributions!

zulipbot avatar Apr 18 '21 12:04 zulipbot

@zulipbot claim

Ponni-M avatar Apr 18 '21 12:04 Ponni-M

Hello @Ponni-M, it looks like we've already sent you a collaboration invite at https://github.com/zulip/python-zulip-api/invitations, but you haven't accepted it yet!

Please accept the invite and try to claim this issue again afterwards. We look forward to your contributions!

zulipbot avatar Apr 18 '21 12:04 zulipbot

@zulipbot claim

jayfangjz avatar Nov 10 '22 22:11 jayfangjz

Welcome to Zulip, @jayfangjz! 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)!

zulipbot avatar Nov 10 '22 22:11 zulipbot

@zulipbot claim

aditicodess avatar Sep 05 '23 07:09 aditicodess

Welcome to Zulip, @aditisinghchauhan! 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)!

zulipbot avatar Sep 05 '23 07:09 zulipbot

Hi there! 👋

I hope this finds you well. I came across this intriguing issue and I'm eager to contribute to the project. Could you please confirm if this issue is still open and available for work?

If it is, I'd love to take a shot at resolving it. Could you kindly assign this issue to me? I'm excited to get started and contribute to the project!

Thanks in advance!

kalpeshmarathe avatar Dec 16 '23 08:12 kalpeshmarathe

@zulipbot claim

kalpeshmarathe avatar Dec 16 '23 08:12 kalpeshmarathe

Welcome to Zulip, @kalpeshmarathe! 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)!

zulipbot avatar Dec 16 '23 08:12 zulipbot

@kalpeshmarathe 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!

zulipbot avatar Dec 26 '23 09:12 zulipbot

@zulipbot claim

sofiavalb avatar Apr 02 '24 19:04 sofiavalb

Welcome to Zulip, @sofiavalb! 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)!

zulipbot avatar Apr 02 '24 19:04 zulipbot

@zulipbot abandon

sofiavalb avatar Apr 02 '24 20:04 sofiavalb