getting images by url
Hi please , am I the only who can't see images stored in the bucket with their id ?
26 Replies
how are you constructing the URL?
storage URLs cannot be constructed directly from an ID. this used to be possible, but it was never intended to work and if there's any documentation describing it, please let us know so we can fix it. the supported way to get a url is
ctx.storage.getUrl(id)
the url to display the image is : https://reminiscent-bulldog-109.convex.cloud/api/storage/da8c6614-b2ed-49b5-843f-d500f98cdd13
but the id is : kg29qaz64q9dyzcythm72w8t7s6nvqdf
correct
when I remove the last part of the url and put the id in the link I got an error.
yes that is not supported. is there any documentation that indicates it's supported?
if that worked, it would potentially be a security hole, because it would make it impossible to add access rules to stored files
2 weeks ago it worked.
yes we patched the security hole 🙂
ok thank you I will use the supported way you showed to me.
btw here's the prior conversation. sorry about the unexpected change.
https://discord.com/channels/1019350475847499849/1019350478817079338/1213139043227934810
exactly , he made a tuto , in which everything used to work.
ctx.storage.getUrl(id), I'm supposed to pass the id of the image ?
ah that makes sense. Thanks for letting us know! Since there's a tutorial maybe we should announce this change somewhere
ctx.storage.getUrl(id) what is id ?
the storage id of the image. In your example, it's "kg29qaz64q9dyzcythm72w8t7s6nvqdf"
ok thank you.
@Lee it's me again , please do you have a sample , an example because I'm a bit lost .
I don't know how to get the id in the convex file and then passing it through the query and displaying it in my App.tsx file.
there's sample code at https://docs.convex.dev/file-storage/serve-files . If you have code that doesn't work, you could also post it with the error and see what's wrong
Serving Files | Convex Developer Hub
Files stored in Convex can be served to your users by generating a URL pointing
1h on that page but still nothing
how are you uploading the file? That should give you a storage id
it's over for me.🥲
uploading is fine , the doc is good . The problem come when I run
ctx.db.query("DataFile").collect();
I got the data in an array how can I pull out the id and then pass it to ctx.storage.getUrl(id)guessing at your schema, maybe this will help
I'm going to test and also thanks for the time you are spending to solve my problem.
In general, you should use the same
storageId
you used to manually generate the URL, to storage.getUrl(:storage_id)
. This will give you the proper URL to use. You should never manually construct the URL.@Lee thank you so much I solved my issue.
Hey @Lee , I'm making the same change to my code right now. How can I tell TS that the ID is of type storageId? I keep running into the fact that passing a string is deprecated. Thanks in advance

can you share your schema? i am imagining you have
which should work
Ah that's my bad. I had it defined as a string in the schema! Moving too quick - thanks a ton