Help forum

[solved] CORS error in a request to Supabase Storage

  • Guilherme Hirsch

    2 years ago

    Hey guys! I copied the application template with the request to upload a file to Supabase Storage. I changed it to my account data, but a CORS error appears in the console, can anyone help me with this?
    1197908260435542137-image.png
    ✅1
    👍1
  • gazinhio

    2 years ago

    Did you tick the Proxy box on the API in the bottom-right of the API set-up? (think it's ticked it by default now). This proxies the call through Toddle's secure server. If not, the call is made through the client/browser and often results in a CORS error as the server doesn't trust the origin of the call.
    🥳1
  • Guilherme Hirsch

    2 years ago

    Excellent! Now the error message is different:
    1197958284771065967-image.png
  • Can you tell me if anything has changed in the Supabase documentation regarding this?
    1197958501100687470-image.png
  • Stockton

    2 years ago

    Looks like you have a space before storage in the path
  • Nvm maybe not
  • Guilherme Hirsch

    2 years ago

    I believe this is not the problem. I put it as POST now and it still has an error.
  • In the template it was as PUT the request
  • Lucas G

    2 years ago

    I haven't used the template but it is possible that some changes have happened to the API since it was made.
  • I need to work on supabase uploads soon too so I'll try it out as well and report back
  • Lucas G

    2 years ago

    Just quickly looking at it, it might be missing the bucket and filename /paths/
  • Lucas G

    2 years ago

    Something else I saw a while back:
    In the request URL https://{ref}.supabase.co/storage/v1/object/{bucket}/{filename.ext} you can actually set {filename.ext} to any filename with extension that you want to use to save the file server-side. It does not have to be the same as the file's local filename.
  • Please let us know if this works
  • Guilherme Hirsch

    2 years ago

    It worked with your recommendations. All you need to do is edit the policies in Supabase. Thank you very much!
  • Tod

    2 years ago

    Great energy @Guilherme Hirsch! Your continuous contribution to the toddle Community just made you advance to Community Level 2!
  • Guilherme Hirsch

    2 years ago

    1197985666965979246-image.png
  • Lucas G

    2 years ago

    Awesome, good to know
    😉1
  • Mark it as solved in case this can help others too 👍
  • Guilherme Hirsch

    2 years ago

    [solved] CORS error in a request to Supabase Storage
  • unicodes

    2 years ago

    @Guilherme Hirsch can you please share the policies you used in Supabase?
  • asad

    2 years ago

    👀
  • Lucas G

    2 years ago

    Policies should be whatever you need them to be. Allow anon if it's meant to be a public bucket otherwise it should verify users the same as your other tables
  • Lucas G

    2 years ago

    Enter your policies in the 'Storage' options in the Supabase backend, right under where you create the bucket
  • Normally, you add them to the 'Objects' field
  • asad

    2 years ago

    @Lucas G is there in any tutorial on the Supabase Upload Input i can't figure it out
  • Lucas G

    2 years ago

    The package? Should be a matter of entering your supabase details and that’s it 🤔
  • asad

    2 years ago

    what am i missing
    1284912009216786493-image.png
  • Lucas G

    2 years ago

    DM me your project if you can
  • Did the component send anything back in the event?
  • Lucas G

    2 years ago

    It was an RLS issue why the upload wasn't working ^
  • unicodes

    2 years ago

    @Lucas G I get the error CORS, and it is very strange because everything is identic with avatar, but for avatar works and for covers doesn't. Do you have any ideea why it doesn't work if everything is identic avatar = covers? https://discord.com/channels/972416966683926538/1284793988758376458
  • unicodes

    2 years ago

    I'm full o policies, but still receiving the CORS error.
    1284943239547457607-Screenshot_2024-09-15_at_21.24.21.png
    1284943239844987022-Screenshot_2024-09-15_at_21.25.01.png
  • Lucas G

    2 years ago

    The policies wouldn't matter for CORS
  • Not related