© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3mo ago•
36 replies
Wes

Cannot delete files from storage bucket

I've looked through previous questions and they all seem to be solved via RLS changes. I've tried every policy I can think of and still cannot delete files from a bucket, either via code or thru the dashboard.


Here is my current policy, this is the only one that exists in the storage section. I'll change it to be more restrictive once I figure out what is stopping me from being able to delete files.

CREATE POLICY "An authenticated user can CRUD any files"
ON storage.objects
FOR ALL
TO authenticated
USING (bucket_id = 'test');
CREATE POLICY "An authenticated user can CRUD any files"
ON storage.objects
FOR ALL
TO authenticated
USING (bucket_id = 'test');


When I try to delete a file via the dashboard, it just hangs with a spinner saying
Deleting 1 file(s)...
Deleting 1 file(s)...




Here is a sample function that demos the problem I have trying to delete via code, plus a screenshot of the console output. I get a response saying
StorageApiError: The related resource does not exist
StorageApiError: The related resource does not exist
, but I pulled the data straight from a query so I know the file is there and the name is correct.

async function deleteTest({ bucket, folder }) {
    console.log("Running deleteTest for bucket:", bucket, "folder:", folder);

    const { data: listData, error: listError } = await supabase.storage
      .from(bucket)
      .list(folder, {
        limit: 2,
        sortBy: { column: "name", order: "desc" },
      });

    if (listError || !listData) {
      return;
    }

    console.log(`Files in ${bucket} bucket, ${folder} folder:`, listData);

    const fileToDelete = `${folder}/${listData[0].name}`;

    console.log("Deleting file:", fileToDelete);

    const { data: deleteData, error: deleteError } = await supabase.storage
      .from(bucket)
      .remove([fileToDelete]);

    console.log("Delete file error: ", deleteError);
  }
async function deleteTest({ bucket, folder }) {
    console.log("Running deleteTest for bucket:", bucket, "folder:", folder);

    const { data: listData, error: listError } = await supabase.storage
      .from(bucket)
      .list(folder, {
        limit: 2,
        sortBy: { column: "name", order: "desc" },
      });

    if (listError || !listData) {
      return;
    }

    console.log(`Files in ${bucket} bucket, ${folder} folder:`, listData);

    const fileToDelete = `${folder}/${listData[0].name}`;

    console.log("Deleting file:", fileToDelete);

    const { data: deleteData, error: deleteError } = await supabase.storage
      .from(bucket)
      .remove([fileToDelete]);

    console.log("Delete file error: ", deleteError);
  }
supabase_delete_error_2.png
supabase_delete_error.png
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Not able to download files from storage bucket
SupabaseSSupabase / help-and-questions
2mo ago
Delete user files in storage bucket when user is deleted.
SupabaseSSupabase / help-and-questions
3y ago
Storage bucket problem
SupabaseSSupabase / help-and-questions
3mo ago
Bucket Storage Namespacing
SupabaseSSupabase / help-and-questions
6mo ago