3

I've been trying to update a single file within a folder in the bucket that i created but when i go to update with a new image from the front does not update the image and gives the following error. statusCode: "404", error: "Not found" Then when i went to check the route of the call it seems to be wrong http://localhost:54321/storage/v1/object/xxx-images/xxx_image/36a75358-8612-4e0e-96d8-76e4f579b80d.jpg. So after checked the route i went to the bucket and copy the route from the image uploaded and the route is different from the route of the call previously mentioned http://localhost:54321/storage/v1/object/public/xxx-images/xxx_image/05f9d208-bab2-45ab-a355-71ba4a41cf59.jpg. As you can see the route from the image saved on the bucket has the /public/ word on the route. I took the api call to update from the documentation docs and the api call on the front that i have made is the following:

     const { data, error } = await supabase
      .storage
      .from('xxx-images')
      .update(`xxx_image/${oldPresentationImage}`, presentationImage.file, {
        contentType: 'image/png'
      });
    if(error) {console.log('error ', error)};

I don't get why the route is not the same when i call the api update method from the front. I'm using the version 1.1.0 and i got the policies for authenticated users

Richi
  • 438
  • 5
  • 18

1 Answers1

1

The public keyword in the URL of your uploaded image just means that it's the public URL of the image.

The documentation is correct, and you do not need a public keyword inside of your code for updating.

The issue probably here is that you don't have select policy set for your storage.objects table. As the docs says, you need both update and select permission to perform update call.

objects permissions: update and select

dshukertjr
  • 15,244
  • 11
  • 57
  • 94
  • Thanks for the response. I’m only having the problem that the image file name is only updating on the db but is not updating on the bucket, I keeps the same old name but the image changed – Richi May 02 '23 at 00:12
  • 1
    If you want to change the name of the image, `update()` would not work. `update()` is used to update the meta data and stuff for an existing image. If you want to change the image name or image location, you want to use `move()`. https://supabase.com/docs/reference/javascript/storage-from-move – dshukertjr May 02 '23 at 01:35
  • Maybe I can keep the same file name and change the meta data, but I had to open a incognito window to see the change of image – Richi May 02 '23 at 03:14