Skip to content
Init is coming / May 10 - 14
Back

getFileView() returns 401 Unauthorized even when user is authenticated and has read permission

  • 1
  • Self Hosted
  • Web
  • Storage
  • Cloud
daniD
27 May, 2025, 06:09

Description:

I’m encountering a 401 Unauthorized error when attempting to access a file URL returned by storage.getFileView(...), even though the user is authenticated and has been granted the appropriate read permission on the file.

Steps to Reproduce: 1. A logged-in user uploads a file to a bucket using Appwrite’s Storage API. 2. The collection is assigned read permissions to a specific user (read("user:USER_ID")) or team (read("team:TEAM_ID")) (file level security is disabled). 3. I retrieve the file view URL using:

const url = await storage.getFileView(bucketId, fileId);

TypeScript
4.    I try to open this URL (e.g., in a new browser tab).
5.    I get the following response from the server:

{ "message": "The current user is not authorized to perform the requested action.", "code": 401, "type": "user_unauthorized" }

What I Expected:

I expected the returned getFileView URL to load the file as the authenticated user has read permission and is logged in.

What Actually Happened:

The URL returns a 401 Unauthorized unless I either: • Set the permission to read("any"), or • Append &mode=admin (which works only in the same session with an active session cookie I get 401 on incognito mode).

Environment: • Appwrite Version: 1.6.1 • SDK: Web SDK (Vue 3 + Nuxt) • Deployment: Self-hosted (Docker) • Auth: Email/password login with session By the way, I can delete the file without problem.

TL;DR
Developers are experiencing a 401 Unauthorized error when attempting to access a file URL using getFileView(), despite being authenticated and having read permission. The issue seems to be related to the permission settings for file access. A workaround includes setting permissions to read("any") or appending &mode=admin.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more