Skip to content

File Upload & Resource Management #3

@codeCraft-Ritik

Description

@codeCraft-Ritik

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions