-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Issue:
The uploadFileWithProgress function uses the original file name in the storage path: images/${user.id}/${file.name}.
Summary:
Every time a user uploads a new profile picture with a different filename, the old file remains in the Supabase bucket, consuming unnecessary storage space.
How to Fix:
Standardize the filename(e.g., profile_image)so that every new upload automatically overwrites the previous one in storage.
Code Implementation:
// src/provider/supabaseProvider.jsx
const uploadFileWithProgress = async (file, onProgress) => {
if (!file || !user?.id) return;
const bucket = "files";
// Standardize the name to 'profile_image' to force overwriting
const fileExtension = file.name.split('.').pop();
const path = `images/${user.id}/profile_image.${fileExtension}`;
try {
const { data: urlData, error: urlError } = await supabase.storage
.from(bucket)
.createSignedUploadUrl(path); // This will overwrite if the path matches
// ... rest of XHR upload logic
} catch (err) {
console.error("Upload error:", err.message);
}
};
Metadata
Metadata
Assignees
Labels
No labels