How to retrieve files from the Storage in Convex
code:
error:
Dec 07, 19:53:04
Q
queries/packageTable:getPackageById
failure
33ms
Uncaught TypeError: ctx.storage.get is not a function
at handler (../../convex/queries/packageTable.ts:37:31)
4 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
See the docs,
ctx.storage.get
doesn't exist (EDIT: in queries and actions, thanks Lee), there's .getUrl()
and .getMetadata()
https://docs.convex.dev/api/interfaces/server.StorageWriter#methodsgot it, thanks!
ctx.storage.get
only exists in actions, not queries or mutations. The philosophical reason it doesn't exist in queries is that queries are for small, reactive data processing (they have strict limits on runtime and how much they can read), while stored files may be large.
But if you want to write an action that does ctx.storage.get
, that should work
But as Tom suggested, the typical flow is to do ctx.storage.getUrl
in a query and then use the url from the client