Search code examples
supabase

Can't delete file from bucket supabase-bucket


I am trying to delete a file from a bucket from which I have created two policies, although I can save in the bucket I cannot delete the data, it returns data: []

my code is:

    const deleteVideoFromBucket = async(videoFile) => {
        const videoFilePath = videoFile.split('/').pop();
        console.log(videoFilePath)
        try {
            const { data, error } = await supabase
            .storage
            .from('video_course_presentation')
            .remove([`${videoFilePath}`])
            console.log('return', data, error)
            if(data && data.length > 0) {
                videoDeletedFromBucketToaster();
            }

        } catch (err) {
            console.log('There was an error deleting the video file from the bucket ', err);
        }
    }

Solution

  • My mistake i was missing a select policy with the delete.

    CREATE POLICY "Select video can be done only for authenticated users" 
    ON storage.objects FOR SELECT TO authenticated USING 
    (bucket_id = 'video_course_presentation');
    
    CREATE POLICY "Delete video can be done only for authenticated users" 
    ON storage.objects FOR DELETE TO authenticated USING 
    (bucket_id = 'video_course_presentation');