Hey everyone,
I’m working on a project using WeWeb as my frontend and Supabase for my backend. I’m tackling image uploads for user profiles, specifically for an “Users-Profile” table.
Here’s what I’m trying to achieve:
Store images in Supabase Storage: Each user should have their own dedicated folder within a specific bucket (e.g., users-images/user_id/).
Sync image URLs to a PostgreSQL array: The public URLs of all images in that user’s folder should automatically populate an images (text array) column in their corresponding row in the public.Users-Profile table.
I’ve been thinking about using a Supabase Edge Function triggered by Storage events to handle this. My idea is that whenever a file is uploaded or deleted in a user’s Storage folder, the function would read all files in that folder, generate their public URLs, and then update the images array in the Users-Profile table for that specific user.
This approach seems promising because it would automatically manage:
- Initial image uploads when a profile is created.
- Modifications to a profile, like when a user deletes an image or adds a new one.
- Keeping the logic off the WeWeb frontend and centralized in Supabase’s backend.
Has anyone implemented a similar solution or have experience with this pattern in Supabase? I’m particularly interested in:
The exact setup for the Database Trigger (how to get it to listen to storage.objects and trigger an Edge Function).
Best practices for writing the Edge Function to list files and update the PostgreSQL array.
Any potential pitfalls, performance considerations, or alternative approaches I should be aware of.
Any insights, code examples, or conceptual explanations would be greatly appreciated!
Thanks in advance for your help.