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

How to let API user access uploaded files? #22227

Open
hongquan opened this issue Jun 9, 2022 · 10 comments
Open

How to let API user access uploaded files? #22227

hongquan opened this issue Jun 9, 2022 · 10 comments

Comments

@hongquan
Copy link

hongquan commented Jun 9, 2022

We have a web application where we leverage Zulip to build chat feature. We created a chat box in our web application and calling Zulip API to receive and send chat messages. The problem is that when one user sends a file, other users in the same stream cannot access the file, getting "You are not authorized to view this file" error, if view from our front-end.

How can I make the files accessible?

@cmprmsd
Copy link

cmprmsd commented Jun 23, 2022

See this bug here: #22285

To make an uploaded file available to other users you must send the link in a chat message to them or the stream and this has to be in the format:

[](/path/after/domain/file.ext)

Zulip will recognize the file and update the permissions accordingly. That's at least what I noticed. :)

@alya alya added the question label Jun 27, 2022
@alya
Copy link
Contributor

alya commented Jun 27, 2022

@hongquan does the above address your question?

@hongquan
Copy link
Author

hongquan commented Jun 28, 2022

@alya @cmprmsd Not address my case.
In my case, the URL I acquired via Zulip message API is relative URL (without https://domain), I have build absolute URL from it, so there is no case of duplicate "/".

@hongquan
Copy link
Author

Note that, in my case, file is uploaded in Zulip web UI (https://utar.chat.fairwiz.com), and on our website (https://some-other-domain.com), we call Zulip API to get message and display to user. Before displaying to user, we have to rewrite the URLs in the message content, converting them from relative to absolute. The rewriting must be made so that browser doesn't think the files are in the https://some-other-domain.com domain.

@cmprmsd
Copy link

cmprmsd commented Jun 28, 2022

After the file has been uploaded, do you share it with Zulip in the chat stream?
It seems you are trying to access the file anonymously. Not sure if this will work in any case.

@hongquan
Copy link
Author

hongquan commented Jun 28, 2022

@cmprmsd I don't understand this question:

After the file has been uploaded, do you share it with Zulip in the chat stream

Because as I descibed, we attach the file with the chat in Zulip web UI. There is no explicit "share" button/ action.

image

It seems you are trying to access the file anonymously

Yes, and the problem is that I don't know how to authenticate user to access the file, because the message is retrieved via Zulip API. We have the email addess + API key to call API. But with that credentials, Zulip doesn't mark the session as "authenticated" to let me access the file.

@cmprmsd
Copy link

cmprmsd commented Jun 28, 2022

Has the bot been joined to the channel/stream where you post the file?
This was a mistake I did on my first try, too 😁

@hongquan
Copy link
Author

@cmprmsd Yes. I did let the bot/user subscribe to the stream, and I can get new chat message in real-time.

@lgsandy
Copy link

lgsandy commented Jul 13, 2023

We have a web application where we leverage Zulip to build chat feature. We created a chat box in our web application and calling Zulip API to receive and send chat messages.The problem is that when i view from our front-end it is showing 403.
Zulip error
zulip file

@zulipbot
Copy link
Member

Hello @zulip/server-api, @zulip/server-bots, @zulip/server-misc members, this issue was labeled with the "area: uploads", "area: api", "area: bots" labels, so you may want to check it out!

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

No branches or pull requests

6 participants