Maxime
Maxime•13mo ago

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
erquhart
erquhart•13mo ago
Welcome! What approach are you using for uploads? File upload url, uploadstuff.dev, something else?
Maxime
MaximeOP•13mo ago
uploadstuff.dev with the drop file component
erquhart
erquhart•13mo ago
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.tsx
Maxime
MaximeOP•13mo ago
it seems that copying the components is working, i will try to update it to manage my use case
erquhart
erquhart•13mo ago
Ah just realized you said drop file component. Anyway, glad it's working! And hats off to @Michal Srb for exporting all the things 🎉
Maxime
MaximeOP•13mo ago
yeah its working with the dropzone component too
Maxime
MaximeOP•13mo ago
the fix "seems" very simple, i have updated the ondrop function and added a validator function to the property of UploadDropzone
No description
Maxime
MaximeOP•13mo ago
the validator function run after that the lib already have validate the extention's file
Michal Srb
Michal Srb•13mo ago
@Maxime PRs welcome if we can make the existing API more flexible (like adding an optional prop). Thanks!

Did you find this page helpful?