Get the file content before uploading to convex
is there any way to get the file content before upload it to convex ? my upload is limited to json files but i want to validate the file content to prevent any issue with the json uploaded ( mal formatted or bad file )
thx
9 Replies
Welcome! What approach are you using for uploads? File upload url, uploadstuff.dev, something else?
uploadstuff.dev with the drop file component
Looks like the
useUploadFiles()
hook is your best bet, but you'd have to provide the UI. This would be worth opening an issue on the repo for, definitely a case for the component supporting this.
It also looks like you could copy the UploadButton
component file and use it in your project. I haven't tested it, but it looks like the package exports everything you would need to do that. If so, modifying the component locally to do what you want would be pretty trivial.
Component here if you want to give it a shot: https://github.com/xixixao/uploadstuff/blob/main/lib/UploadButton.tsxit seems that copying the components is working, i will try to update it to manage my use case
Ah just realized you said drop file component. Anyway, glad it's working! And hats off to @Michal Srb for exporting all the things 🎉
yeah its working with the dropzone component too
the fix "seems" very simple, i have updated the ondrop function and added a validator function to the property of UploadDropzone

the validator function run after that the lib already have validate the extention's file
@Maxime PRs welcome if we can make the existing API more flexible (like adding an optional prop). Thanks!