Back

How to protect file url

  • 0
  • Self Hosted
  • Web
  • Storage
  • Cloud
Suiii
12 Sep, 2024, 14:35

I generate the url to file in NextJS server action. In client component, i use that url as src image. It works fine when I give Any permission! I want to protect only authorized users are able to access. How can I do so!export function generateFileUrl(bucketId: string, fileId: string) { const apiPath = /storage/buckets/${bucketId}/files/${fileId}/view?project=${PROJECT_ID}; const uri =new URL(API_DOMAIN_URL + apiPath); return uri.toString() } I am thinking to write logic to check at server action, but just reliazed (less chance) , manual type of url , still can acess

TL;DR
To protect a file URL in NextJS from unauthorized access, developers can add logic on the server side to check if the user is authorized to view the file. This can prevent manual entry of the URL for access.
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