Hey folks. I feel like this should be easier - I'm...
# javascript
m
Hey folks. I feel like this should be easier - I'm trying to get the id of a newly created row after uploading an object to storage. Currently I'm: 1. Upload object.
Copy code
let { data, error } = await supabase.storage
        .from("assets")
        .upload(filePath, file);
2. Get list of all assets for a user `const { data: assets } = await supabase.storage .from("assets") .list(
${user.id}
);` 3. Find the id by matching the name column
const newAsset = assets.find((element) => element.name === file.name);
g
You could just do a select on the object table with matches for bucket and name(path/filename) and get back the id. I'm not sure what you need the id for though. If you have the path and bucket you have unique "key" for file and that is what the follow up calls to storage want anyway.
m
I have another (public) table with a foreign key relationship column for object_id. After the object is uploaded I want to add the id to the object_id field.
g
I do a similar thing, but store the bucket/path string. Besides using the id to get the path and bucket for other calls what does this id relationship do for you? You can't just delete the row in the object table (or drop it if parent row is deleted) as that leaves your file data orphaned in storage.
m
Ah. So instead of using id, just use the key? I guess I was just repeating the basics id learned when designing the schema for a db and the tutorial generally linked to the row id.
g
Since the storage interface all uses the bucket and path (key) then having the id is just an extra step to do anything as you would just turn around and have to fetch them with the id before making storage calls.
m
Thank you!