Need help using the uploadstuff api
Hello,
I'm trying to follow the example in the uploadstuff website.
1. I create a convex/files.ts file and paste the code provided.
2. Then I paste the code in the UploadButton to my component.
Instantly I'm getting errors in the convex console.
In this code there is no uploaded arg in the args: property. Don't really understand what I need to pass.
I attach an image with the errors.
The someId error is not a problem, I get it.
Thank you!
24 Replies
I think here should be the storageIds...
I don't know where the variable uploaded came from
Sharing your function code would help, but it looks like the args for your mutation only include
storageIds
. You need to get the listingId
from somewhere (maybe add to args).
Oooh I see the example you're referencing - that looks like a typo, replace args.uploaded
with args.storageIds
It looks like you added listingId
yourself, so you'll want to add that to the function args and then pass it from the call site in your client.Yes, that was it. I suggest you fix that, because is somehow confusing
cc/ @Michal Srb
You may want to read a bit on mutation arguments and validators to better understand the code you're deploying: https://docs.convex.dev/functions/validation#adding-validators
Argument and Return Value Validation | Convex Developer Hub
Argument and return value validators ensure that
oh you got it 🫡
Thank you erquhart!
Are you intentionally avoiding using
v.id()
to validate the listing id?Is there any benefit using the v.id()?
It validates something?
It does what you're doing with normalize id
Oh, nice
I'd gather you should be able to make listingId a required field and just use the id validator for the args here.
I don't need to normalize if I use it?
Are you passing in strings that might not be valid convex ids?
The convex libraries for client and server both provide id validation, so you shouldn't need to manually normalize unless it's part of a more complicated system, probably involving an external system.
No I'm not
Got it
Good to know that
How do you recommend to handle the error?
Should I do a try catch block?
If the id not exists, will throw an error?
Unless there's a scenario where the id might not exist, this should cover it.
I add the
v.id('_storage')
bit, which I think works, but the fact that it wasn't used in the example in the docs makes me wonder if maybe it doesn't.
Try replacing it with v.string()
if it gives you trouble.Ok, I'll try it
Should I save the sotrageIds in one array in the table? Will that make a problem if the user wants make CRUD them?
Beacuse they don't have separated Ids
Thats what the example is doing
Not fully understanding your question, but it is valid to store the ids in an array. They'll remain distinct and can still be used relationally. Whether that's the right approach depends on your use case.
What if the user needs to delete an image? Every listing has multiple images. Whats the process of doing that?
I need to send the image url, and the delete it with a filter function? and rewrite (replace everything) with the new array?
Yes, that's exactly the process, but it's quite simple
Convex's API is almost like manipulating in-memory storage. So simple it's confusing lol
Thank you @erquhart appreciate your time to explain!
v.id("_storage")
should work (let us know if it doesn't). I think uploadstuff was created before we exposed the _storage
system table, so it's just a historical reason that the best available at the time was v.string()
Docs fixed (I noticed another typo in the each component's docs). Thanks!