nhost
nhost copied to clipboard
Can't update an already uploaded file in NHost Storage
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
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}`,
}
})
Yea, we have the support in Storage but we don't have a method for it in our SDK which we should.
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.
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.
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.