`const avatarFile = event.target.files[0] const { ...
# off-topic
d
Copy code
const avatarFile = event.target.files[0]
const { data, error } = await supabase
  .storage
  .from('avatars')
  .upload('public/avatar1.png', avatarFile, {
    cacheControl: '3600',
    upsert: false
  })
What does the filepath refer to here? Anyone? Edit: This is from the
f
Do you mean the file
public/avatar1.png
in your example? This is the path of the file inside the bucket (
avatars
in this case). The bucket is like a folder on your operating system, so the filePath is the path or folder structure inside this folder.
d
Hey thanks, but if I have an empty bucket with only a folder I mean I am so confused by this honestly and it doesn't seem a hard thing to comprehent. This example
.upload('public/avatar1.png', avatarFile...)
looks if the avatar1.png file is already there even if I just created a new bucket. What happens I point my file to this path? You know what I mean I am so comfused. Or does it just imply that after you'd upload the image that filepath would be created inside Supabase storage but then that doesn't make any sense to push another file where another "file" already is, you'd want to push a file in a folder not a file? Sorry I am as confused as my message here thanks for taking the time!
Edit: creating some spacing for readability or for every image I upload I need to speciffically create the path a file object will be saved at, this is what it does?
but then if I want to upload multiple files at once? I would need to increment some variable in there using sring literals perhaps and fill in paths and files? THANKS
f
Hey 👋 when you create the bucket, the bucket is empty. Imagine creating a new, empty folder on your os. when you upload a file, supabase creates that file inside of the folder. if the filePath contains some "/", supabase automatically creates those subfolders. every filePath / fileName must be unique inside of the folder. there can only be one
public/avatar1.png
file. If you try to upload a file with the same path again, there will be an error. if you want to store the user's avatar for example, consider using the uuid of the user as part of the filePath. for multiple files, consider creating some sort of unique id for the files. you can nest them inside of a folder.
public/user_3d280bcb-9ae6-4b05-960d-7194981fb7e5/5ca68ee8-adfb-4bc9-b300-46d51a9c0da5.pdf
public/user_3d280bcb-9ae6-4b05-960d-7194981fb7e5/2117ed4f-6717-4c8d-b0d6-cd66b9279cbc.pdf
and so on
d
Hey thanks again, Yeah I got the concept... it makes total sense. it's just that the documentation is very lean It says => "The relative file path. Should be of the format folder/subfolder/filename.png" So it basically says the relative file path(fullstop) and in what format it should be and that's it, nothing less nothing more but it doesn't connect this with the actuall example code above it (what is what and what is referring to where) for firstTimers that is a disaster the way this is written, very implicitly, in my humble opinion, it's not explicit enough it assumes that eveyrybody that will read this has been exposed on how to work with uploading images somewhere online before. Which is not the case. It doesn't tell you specifically that YOU will have to put a path which is (HERE in the code example) for EVERY image you upload in a particular bucket/folder. Of course I understand this is the only actual path in the code example but still it is implicitly assumed. Anyway long story short, thanks for the uuid tip, that should work well for avatar images I suppose when the user can only upload one at a time. Take care and thanks a lot!
a
Have you read an IBM documentation? It's like the total contrary of Supabase docs.
d
Hey hi, Not really but to be honest I really am a freshman unfortunately.
You could probably tell 😛
a
Had to work with old ass IBM Database at internship before, worst thing ever
imagine having a slightly different SQL syntax from Postgres and MySQL
d
Yeah I would imagine knowing a lot about something but for somereason now you have to do it just a little bit differently this time or something like that... Supabase is really nice though
Do you think that in order for one to use the product (Supabase) should really get into SQL in order to be really succesful with it? For example I have just a slight exposure to SQL, it looks simple enough(until it's not) but would it be wise to learn it proper in order to use Supabase? What is your opinion on this? Thanks!
a
if you don't care about data optimization yet like I am, I just use it like a glorified 2d array lol
d
Alright I guess you learn as you need as one said. Thanks take care!