Can't interact with files in storage (StorageApiError: Object not found)

When I try to download files manually uploaded to storage buckets in sveltekit I get the error StorageApiError: Object not found. I already tripple-checked every spelling of bucket name and filepath and it is all correct. I know that supabase is responding because I have another page that gets text from a table and it does that no problem. The storage bucket has no policies because I want it to be accessible by everyone since my app doesn't require an account. Technical information:
npm: '10.2.4' node: '21.5.0' supabase: '1.131.3' svelte-kit: '1.2.0'
Full error message
StorageApiError {
__isStorageError: true,
name: 'StorageApiError',
status: 400,
stack: 'StorageApiError: Object not found\n' +
' at /Users/███████████████/██████████████/███████████/node_modules/@supabase/storage-js/dist/main/lib/fetch.js:22:20\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)',
message: 'Object not found'
}
StorageApiError {
__isStorageError: true,
name: 'StorageApiError',
status: 400,
stack: 'StorageApiError: Object not found\n' +
' at /Users/███████████████/██████████████/███████████/node_modules/@supabase/storage-js/dist/main/lib/fetch.js:22:20\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)',
message: 'Object not found'
}
P.S: If it wasnt clear already I'm using SvelteKit
7 Replies
garyaustin
garyaustin2y ago
You have to have some sort of policy to work. No policy means no access. So you can just have the bucket_id = 'name' for all the policies. Also if you allow everyone to access your storage (or database) and ever release your anon key and url (like for browser client) then someone could use up all your storage or database. Normally you want to limit what anon users can do. If this is a public bucket then you can have a URL to access the file directly with getPublicUrl(). But all other operations still require policies.
Macko++
Macko++OP2y ago
so I just need to add the bucket_id = 'name' to this area?
No description
Macko++
Macko++OP2y ago
also, can you give me any recomendations on what policies to write in order to keep the database safe but still allow anon users to upload images and see them?
garyaustin
garyaustin2y ago
I don't know of way to allow anon uploads and have it be safe. How will you stop someone for uploading files if you don't know who they are?
Macko++
Macko++OP2y ago
thats a good point, I will attempt to add account functionality later. When I do, what policies should I add?
garyaustin
garyaustin2y ago
You at a minimum have ability to say only users who have joined your site can upload and so can stop them if they do bad things. This is all based on Supabase Auth roles and user ids.
Macko++
Macko++OP2y ago
Alright, thanks!

Did you find this page helpful?