I am trying to download a file from a public bucke...
# help
d
I am trying to download a file from a public bucket
publicfiles
using this function:
Copy code
const downloadFile = async (pathToFile) => {
    const { data, error } = await supabase
      .storage
      .from('publicfiles')
      .download(pathToFile)
    if (error) throw error
    return data
  }
I logged out
pathToFile
and the Url seems to be correct since I can view the image in my browser. The error I'm getting is:
Copy code
Uncaught (in promise) 
{message: 'Access Denied', status: 400}
message: "Access Denied"
status: 400
[[Prototype]]: Object
My bucket is public and I'm using the standard
Enable read access for all users
SELECT
policy for storage.objects. (public bucket itself has no policies) Is there anything else I need to do?
n
Hello @daviscup! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g
public setting only applies to the public url. All other storage operations need RLS policies set to allow access even on public buckets. So download needs RLS a valid RLS policy. pathToFile is the path and not a URL in case that is what you used. I think you are saying you do have RLS policy set to true on all objects, which should allow download though...
d
Oh, I see. Yeah, I'm storing the public Url in my database right now and trying to use it for my file download:
Copy code
const { publicURL, error } =        supabase.storage
            .from('correctionfiles')
            .pathToFile(filePath)
I can't find
pathToFile
anywhere in the documentation. Do I need to use
from.createSignedUrl()
in this case?
yeah right, this is my policy right now for the bucket and storage.objects
g
I don't know what .pathToFile() is. Filepath is the entire name (with folders) of the file. So everything after bucketname/ in the url. Also when you show policies you need to show the actual policy versus just the title of the policy as the actual policy could be totally different.
n
Thread was archived by @daviscup. Anyone can send a message to unarchive it.