nhost icon indicating copy to clipboard operation
nhost copied to clipboard

Can't update an already uploaded file in NHost Storage

Open bcdrme opened this issue 2 years ago • 4 comments

I was trying to update the content of a file I already uploaded, fileId is known:

const { upload } = useFileUpload()
...
await upload({ id: fileId, file })

This doesn't work, it throws 400, duplicate key, this file already exists.

Apparently Hasura Storage allows it, it would be great if it was integrated in the JS SDK as well (and @nhost/react @nhost/nextjs ofc)

Johan Eliasson I think it's supported to update an existing file in Hasura Storage: https://editor.swagger.io/?url=https://raw.githubusercontent.com/nhost/hasura-storage/main/controller/openapi.yaml#:~:text=Replace%20an%20existing%20file%20with%20a%20new%20one (check the PUT operation). Maybe we can re-use nhost.storage.upload() and, as you did, require the user to specify a file id and also specify an optional { update: true } or something

bcdrme avatar Jan 06 '23 10:01 bcdrme

I can confirm this works using fetch :

const formData = new FormData()
formData.append('file', file)
await fetch(`/api/files/${fileId}`, {
    method: "PUT",
    body: formData,
    headers: {
        'Authorization': `Bearer ${token}`,
    }
})

bcdrme avatar Jan 06 '23 11:01 bcdrme

Yea, we have the support in Storage but we don't have a method for it in our SDK which we should.

elitan avatar Feb 09 '23 08:02 elitan

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 08 '23 08:08 stale[bot]

I would also like to update an existing file.

My use case is downloading word docs, making some changes and reuploading them. I have the file_id, but useFileUpload provides no "overwrite" mechanism.

mainstreetmark avatar Oct 18 '23 14:10 mainstreetmark

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 16 '24 14:04 stale[bot]