PricingBlog

Upload an Image to Supabase

  • uunicode-1270322590711414855

    unicodes

    1 year ago

    I have two situations, uploding an image from an input and uploading an image from a url (from internet) to supabase. Is there someone available to create a package for uploading images or creating a short video tutorial? Thank you!
  • lucasg-1270379134496804866

    Lucas G

    1 year ago

    There is already a video made by toddle's Erik
  • You should be able to replicate it
  • I think he's posted the project somewhere as well
  • That link might be helpful for the API
  • Supabase's storage API isn't very well documented at the moment but thankfully Erik made that video a while back
  • lucasg-1270380505031770192

    Lucas G

    1 year ago

    The main things to note are that you'll want to use the 2-step approach (request signed key, then upload) as the upload call is unproxied
  • lucasg-1270381099637538857

    Lucas G

    1 year ago

    Since you can't send big call's through their servers (aka upload files)
  • lucasg-1270381470594367548

    Lucas G

    1 year ago

    And for an upload from a different URL, that involves a few extra steps and might likely require a custom action
  • uunicode-1270382530058780774

    unicodes

    1 year ago

    I tried the follow the video of Erik for the upload from a different url, not normal select and upload from local. It wasn't a success. Yes, the documentation isn't the best, I have to try again. What solution do you use for you apps regarding uploading images and storing them? Maybe is out-there something better or easy to implement.
  • lucasg-1270382694169313353

    Lucas G

    1 year ago

    I use something very similar
  • Using supabase storage for now with a bit of cloudflare R2. Depending on the use case
  • My upload component is vanilla though, no third-party libraries
  • uunicode-1270383016358838273

    unicodes

    1 year ago

    You use like javascript code "vanilla though"?
  • lucasg-1270383062022094889

    Lucas G

    1 year ago

    No JS needed
  • All done with toddle actions
  • Ah actually, I think I have a simple custom action**
  • I have one to check file size
  • Since I limit it
  • uunicode-1270383923951833098

    unicodes

    1 year ago

    Wow, great work if you did this in toddle. It is possible to share some screens? I'm curios to understand how you get the file data and then how you made your checks "size, weight, etc".
  • lucasg-1270384908493394002

    Lucas G

    1 year ago

    I'll try to share some when I get teh chance
    🙏1
  • Erik's video will get you most of the way there
    🙏1
  • uunicode-1270385102689669212

    unicodes

    1 year ago

    Thank you Lucas for you help 🙏
  • uunicode-1270454086919131197

    unicodes

    1 year ago

    I receive the error "Invalid Key" 400. Do you know how to fix this error? I'm using the same apikey as pe db, in storage there is only the s3 apikey but the tutorial was made without s3.
    1270454086533386357-Screenshot_2024-08-06_at_21.47.29.png
  • lucasg-1270463357354381405

    Lucas G

    1 year ago

    No need for S3 keys
  • First request is made using regular bearer token with anon apikey
  • The response body will have a url and a token
  • The upload call uses that token instead and no bearer auth token since it is unproxied
    🥰1
  • uunicode-1270464889558663252

    unicodes

    1 year ago

    Found the issue, it was from a error typing. Now it saves the image as text plain 😅. It should be from content type, but it is already set to multipart/form-data
    1270464889424580618-Screenshot_2024-08-06_at_22.32.39.png
  • uunicode-1270470228324913182

    unicodes

    1 year ago

    this is how I store the file data in the variable.
    1270470228110999552-Screenshot_2024-08-06_at_22.54.27.png
  • lucasg-1270479258376077423

    Lucas G

    1 year ago

    Alright I quickly put the component as a package
    🥰1
  • Try it out to see if it works
  • It was made for the needs of that project
  • And I haven't modified it to make it more 'generic'
  • uunicode-1270703015095173172

    unicodes

    1 year ago

    Hi Lucas, today with the help of Erik I found the issue (uncheck Proxy). Now it works selecting an image from local and uploading it. I would like to improve this and process also urls (image from internet url). Is your package doing this? I have no ideea from where to start doing this :).
  • lucasg-1270763037997006979

    Lucas G

    1 year ago

    Ah that is what I meant by unproxied.
    🥰1
  • Glad you figured it out
  • And no, it only handles local uploads (single or multiple)
  • To fetch external URLs, you'd have to use a custom action or perhaps a third-party library might make it easier
  • uunicode-1270798518776365066

    unicodes

    1 year ago

    Sorry Lucas, "unproxied" just today added it in my vocabulary 😅 .
  • alexsiale_17363-1270811076300116038

    Alex

    1 year ago

    Awesome, where is the package?
  • alexsiale_17363-1274564866149056592

    Alex

    1 year ago

    Hey @Lucas G 🙂

    I have set up Erik's version in my project, everything looks fine and I think it's working, but my GET SIGNED URL call is returning a RLS policy error, see attached.

    How have you set up your RLS policy for buckets?
    1274564865926627390-Screenshot_2024-08-18_at_2.54.33_PM.png
  • This is what I have so far... don't know if it's correct?
    1274564998244597801-Screenshot_2024-08-18_at_3.06.02_PM.png
  • lucasg-1274565136958357515

    Lucas G

    1 year ago

    For me I only allow authorized users to access it
  • lucasg-1274565529293557781

    Lucas G

    1 year ago

    If you don't care about having anyone be able to access it then that should be fine
  • lucasg-1274566133025996800

    Lucas G

    1 year ago

    Oh also my policies are set for objects
  • 1274566137648250900-image.png
  • alexsiale_17363-1274566160934768692

    Alex

    1 year ago

    Yep, I'd like to do the same
  • Oh okay... let me check mine
  • lucasg-1274566344796278845

    Lucas G

    1 year ago

    On the left panel, under storage -> policies
  • I only have it set for storage.objects
  • lucasg-1274566664016629873

    Lucas G

    1 year ago

    Since for me, the main thing I care about is that they cannot access objects without auth (in my case, access is at account level, not user)
  • alexsiale_17363-1274566675185926185

    Alex

    1 year ago

    okay I'll change mine
  • do have actual 'roles' set up?
  • So just the middle set of policies?
    1274566973371715584-Screenshot_2024-08-18_at_3.13.58_PM.png
  • lucasg-1274567102203691119

    Lucas G

    1 year ago

    That's what I have, yeah
  • Both have RLS on by default iirc
  • But I don't need buckets to be touched, only objects
  • alexsiale_17363-1274567336719941632

    Alex

    1 year ago

    yeah same, only need to upload images
  • I'm still getting the RLS error... hmm does it take time to set in?
  • lucasg-1274567479821209732

    Lucas G

    1 year ago

    No
  • alexsiale_17363-1274567533638320158

    Alex

    1 year ago

    1274567533441191936-Screenshot_2024-08-18_at_3.16.13_PM.png
  • lucasg-1274567572787957894

    Lucas G

    1 year ago

    Maybe check you are logged in
  • alexsiale_17363-1274567664114602017

    Alex

    1 year ago

    yeah checked that... maybe I'm just missing something
  • thanks for helping btw
  • lucasg-1274567717248045086

    Lucas G

    1 year ago

    This one is proxied and uses bearer token right
  • alexsiale_17363-1274569422333546506

    Alex

    1 year ago

    Oh..
  • Hahah
  • alexsiale_17363-1274570230386917388

    Alex

    1 year ago

    Oh okay, it is set up I think?
    1274570230173143040-Screenshot_2024-08-18_at_3.26.54_PM.png
  • alexsiale_17363-1274570614245425163

    Alex

    1 year ago

    Progress maybe... new error
    1274570614262464594-Screenshot_2024-08-18_at_3.28.26_PM.png
  • alexsiale_17363-1274570874669891615

    Alex

    1 year ago

    YAY fixed it
  • the AUTH header was interferring
  • WE HAVE SUCCESS
    1274570957259931688-Screenshot_2024-08-18_at_3.29.49_PM.png
  • Thanks Lucas 🙂
  • alexsiale_17363-1274571294280646788

    Alex

    1 year ago

    To achieve uploading multiple images for like an "image gallery" do you follow the same process but with an array around files? or does the current set up support multiple files?
  • lucasg-1274572074580443171

    Lucas G

    1 year ago

    I don't think the demo one did
  • The one I made does
  • You have to add an attribute to the input to allow multiple
  • And for the uploads, you have to upload each one separately
  • lucasg-1274572971456856084

    Lucas G

    1 year ago

    I did it by basically making a toddle 'for loop' that uploads each one but I'm sure there's more than one way to do it
  • alexsiale_17363-1274573851334017145

    Alex

    1 year ago

    That sounds cool, are you happy to share?
  • My next form needs to have multiple
  • lucasg-1274573949946298479

    Lucas G

    1 year ago

    It's the package I made
  • supabase upload input
  • It has no doc page though lol I rushed it. Extracted my component to a package and published it without anything else 😅
  • alexsiale_17363-1274577733552312321

    Alex

    1 year ago

    Haha
  • Ill search for it
  • lucasg-1274579458006712364

    Lucas G

    1 year ago

    It also doubles up as a download button
  • Let me know how it works
  • alexsiale_17363-1274585341252210699

    Alex

    1 year ago

    Oh amazing I need that too lol
  • alexsiale_17363-1275164695245885471

    Alex

    1 year ago

    Do you have this in the package too? Or are you able to share a screenshot of the workflow?
  • lucasg-1275164991116279828

    Lucas G

    1 year ago

    the package already has it
  • If you install the package, it'll just be the one component
    ❤️2
    🔥1
  • alexsiale_17363-1275210735416512594

    Alex

    1 year ago

    Awesome and it has the looping?
  • alexsiale_17363-1276420028891136042

    Alex

    1 year ago

    @Edwin Paul read this thread too
  • nix.nz-1276462182497779712

    Marko

    1 year ago

    Glad, I found this thread. I’m going through a similar setup at the moment.
  • sanedealer-1276466625985384511

    Edwin Paul

    1 year ago

    Thanks!