PricingBlog

[solved] CORS error in a request to Supabase Storage

  • guilhermehirsch-1197908260137742356

    Guilherme Hirsch

    1 year 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-1197912152196010074

    gazinhio

    1 year 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
  • guilhermehirsch-1197958284997574716

    Guilherme Hirsch

    1 year 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_f-1197974564349681795

    Stockton

    1 year ago

    Looks like you have a space before storage in the path
  • Nvm maybe not
  • guilhermehirsch-1197979987312119878

    Guilherme Hirsch

    1 year 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
  • lucasg-1197982993889898586

    Lucas G

    1 year 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
  • lucasg-1197983417707532359

    Lucas G

    1 year ago

    Just quickly looking at it, it might be missing the bucket and filename /paths/
  • lucasg-1197984072174157894

    Lucas G

    1 year 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
  • guilhermehirsch-1197985609277517928

    Guilherme Hirsch

    1 year ago

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

    Tod

    1 year ago

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

    Guilherme Hirsch

    1 year ago

    1197985666965979246-image.png
  • lucasg-1197987578645844018

    Lucas G

    1 year ago

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

    Guilherme Hirsch

    1 year ago

    [solved] CORS error in a request to Supabase Storage
  • uunicode-1284798062577061922

    unicodes

    1 year ago

    @Guilherme Hirsch can you please share the policies you used in Supabase?
  • asad_90597-1284877316828430388

    asad

    1 year ago

    👀
  • lucasg-1284880531473039431

    Lucas G

    1 year 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
  • lucasg-1284880832229675124

    Lucas G

    1 year 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_90597-1284901063870124094

    asad

    1 year ago

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

    Lucas G

    1 year ago

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

    asad

    1 year ago

    what am i missing
    1284912009216786493-image.png
  • lucasg-1284915161034920060

    Lucas G

    1 year ago

    DM me your project if you can
  • Did the component send anything back in the event?
  • lucasg-1284924538823643239

    Lucas G

    1 year ago

    It was an RLS issue why the upload wasn't working ^
  • uunicode-1284942818497925121

    unicodes

    1 year 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
  • uunicode-1284943240046575626

    unicodes

    1 year 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
  • lucasg-1284944016479227965

    Lucas G

    1 year ago

    The policies wouldn't matter for CORS
  • Not related