Back

How to list user's uploaded file but prevent other to list the files?

  • 0
  • Web
  • Storage
igrir
5 Sep, 2023, 04:25

I am creating a blogging platform where user can post their own images into a bucket. User can also see their list of files. Currently I list all user's file by using storage.listFiles. It worked perfectly, but then I realized user B can also see fetch what user A uploaded. If I made the bucket into "private" and remove anyone to read (set its permission specifically to only use File Permission), then guests cannot see the images inside the post.

Is there any way where user can upload the image file to be publicly available for viewing but not added into storage.listFiles?

TL;DR
The user wants to list their own uploaded files but prevent others from listing files. One solution is to use a database collection to store additional data about the file, including the user who uploaded it. Then, you can filter the list of files by the user's ID. By setting the bucket to "private" and removing read permissions, the uploaded images will not be visible to guests, but they will still be publicly available for viewing.
Drake
5 Sep, 2023, 19:03

What's your concern about the list files?

igrir
7 Sep, 2023, 04:49

I simply don't know how to list only what's uploaded by currently logged in user

igrir
7 Sep, 2023, 04:50

when I used listFiles, it basically list all of the file instead of files that we own πŸ™€

Drake
7 Sep, 2023, 05:01

People typically use a database collection for additional data about a file. In this collection, you can have a createdBy attribute and put the id of the user. Then, you can use list documents with a query to filter by createdBy

igrir
7 Sep, 2023, 05:42

I see... so I need to record when a user upload something with trigger

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