Uploadthing: skip uploading the same file the second time

hello everyone, I need to know how can I check uploading image is already have on our uploadthing file or not? if already have then I don't want to reupload and duplicate. How can can check??
No description
2 Replies
Sabbir Hossain Shuvo
Sabbir Hossain ShuvoOP•12mo ago
I don't want this,,, same files is too many time... 😢
Alky
Alky•12mo ago
I was checking uploadthing docs, and it seems that they have an endpoint where you can check some of the files metadata. Since i also don't know if th current hook supports it, i will give you the suggestion to use a wrapper hook, but maybe it fit on the "onBeforeUploadBegin". Anyway, you can create a wrapper of the hook that returns the same thing as the current hook but proccess the file you're trying to upload. Depending on your service, checking just for the name may be a bad idea, but you could get the name and size of the file, fetch the metadata of the files you already have, and then make a comparison by name and size. Give it a range for the size, since a exact comparison may give you some problems. If you're saving the files URL in a MySql database, you may want to create a ImageData table, where you store the URL and the others metadata you want, sou you will not exhaust the upload thing api, and do the checks against your own DB. Just make sure to update it on side effects or make some kind of sync sporadically. I would first try to do it inside "onBeforeUploadBegin", and then create a wrapper for the upload thing hook.
Want results from more Discord servers?
Add your server