Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to upload and overwrite if file already exists. #7

Closed
logikaljay opened this issue May 16, 2021 · 6 comments · Fixed by #15
Closed

Allow the user to upload and overwrite if file already exists. #7

logikaljay opened this issue May 16, 2021 · 6 comments · Fixed by #15
Labels
enhancement New feature or request released

Comments

@logikaljay
Copy link

logikaljay commented May 16, 2021

Not sure if this feature request belongs here, or in the supabase/storage-api repository (or both).

Happy to re-open somewhere else if it doesn't belong here.

Feature request

A user should be able to include a flag in the FileOptions to replace/overwrite the file if it exists on upload.

Is your feature request related to a problem? Please describe.

When I upload a file that already exists, I get an error:

{
  "statusCode":"23505",
  "error":"Key (bucket_id, name)=(tenant-1, dynamic-logo.gif) already exists.",
  "message":"duplicate key value violates unique constraint \"bucketid_objname\""
}

Describe the solution you'd like

A boolean flag added overwrite added to FileOptions that tells the storage-api that the file being uploaded should overwrite if the file exists at the destination.

Describe alternatives you've considered

  • using from(bucketName).list(fileName) to checking if the file exists in the location before uploading, but this seems like an unnecessary API call.
  • Using a hash of the file to name the file and having a lookup table that maps the hashes of the files to actual file names. This could provide "history" to the file, but would also require a lot of additional boilerplate work for the developer to implement.

Additional context

As I mentioned at the top of the issue, this seems like it would probably need to be implemented in the supabase/storage-api repository, then implemented in all of the client libraries.

@inian
Copy link
Member

inian commented Jun 21, 2021

The backend for this has been implemented. We will need to update storage-js now. We can add upserts in the fileOptions object and it can have a default value of false

const { data, error } = await supabase
  .storage
  .from('avatars')
  .upload('public/avatar1.png', avatarFile, { cacheControl: '3600', upsert: true })

Note the backend hasn't been rolled out to the supabase projects yet. So when implementing this feature, you will need to point to the locally running storage-api

@ankitjena
Copy link
Contributor

ankitjena commented Jun 21, 2021

Although @inian I think, replace or overwrite would be a better flag name then upsert, goes well with upload. WDYT?

@inian
Copy link
Member

inian commented Jun 21, 2021

I am trying to mirror postgrest-js as much as possible. replace or overwrite is friendlier but I would rather keep it consistent now and if there is confusion around this, we can rename methods in both postgrest-js and storage-js to overwrite in the future.

@ankitjena
Copy link
Contributor

if there is confusion around this, we can rename methods in both postgrest-js and storage-js to overwrite in the future.

That sounds good

@kiwicopple
Copy link
Member

🎉 This issue has been resolved in version 1.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@logikaljay
Copy link
Author

Thanks @inian, @ankitjena - you guys rock!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants