Uploadthing file handling
hey everyone!
I am currently using uploadthing to do file uploads (images, audios) from my frontend. I am getting into the following problem:
1. User opens the form.
2. Uploads the file which is sent over to uploadthing storage.
3. User refreshes the page.
In this case, the file has been uploaded to server and is saved but it is not being used by a post or anything. How do I make it so files are deleted if not used. I implemented the uploadthing part long ago. Please let me know if there are new things available that can solve this.
Thank you!
5 Replies
@Boneman Yo my guy! I have the exact same problem. When a admin creates a new product for the store, and leaves / refreshes the page. The images that were uploaded is now in the void costing us unnecessary storage costs 😦
I will let you know if i find a fix. Mabye we should make this an issue on the github, if there is no fix.
I have a solution for this. it's to run a cron job. I'm currently keeping track of all the files that are uploaded in my own database and I can check it that way. I'm not sure if it's good though.
Good idea. That would work for me aswell for now. Still i thibk uploadthing should make a real solution to this.
Definitely. I don't know how this should be done. But I have an approach. It goes something like this. We set a callback URL (route on our server). On uploadthing side, this endpoint is hit after a set number of minutes once a file is uploaded. We get the info on the file (name, Id etc) which we can use to setup our own logic.
What do you think of this?
Sort of like a webhook
But with a delay
Or delay is optional
That would work i guess. I think the correct way is to have a hook from uploadthing like import {UploadFiles} from "utapi"
Then you can simple run UploadFiles(files) when the product was successfully created.
This would ofc mean we would need to use config={{ mode: "manual" }} or something like that so the images would not be automaticly uploaded when you drag'n'drop a file.