fix(storage-uploadthing): files are duplicated to the storage via client uploads (#11518)
When uploading file via client side upload we invalidate it then on the server side with re-uploading. This works fine with most adapters since they just replace the old file under the same key. UploadThing works differently and generates a new key every time. Example of the issue: <img width="611" alt="image" src="https://github.com/user-attachments/assets/9c01b52a-d159-4f32-9f66-3b5fbadab7b4" /> Now, we clear the old file before doing re-upload.
This commit is contained in:
@@ -12,8 +12,18 @@ type HandleUploadArgs = {
|
||||
}
|
||||
|
||||
export const getHandleUpload = ({ acl, utApi }: HandleUploadArgs): HandleUpload => {
|
||||
return async ({ data, file }) => {
|
||||
return async ({ clientUploadContext, data, file }) => {
|
||||
try {
|
||||
if (
|
||||
clientUploadContext &&
|
||||
typeof clientUploadContext === 'object' &&
|
||||
'key' in clientUploadContext &&
|
||||
typeof clientUploadContext.key === 'string'
|
||||
) {
|
||||
// Clear the old file
|
||||
await utApi.deleteFiles(clientUploadContext.key)
|
||||
}
|
||||
|
||||
const { buffer, filename, mimeType } = file
|
||||
|
||||
const blob = new Blob([buffer], { type: mimeType })
|
||||
|
||||
Reference in New Issue
Block a user