[Storage] How to handle/bust Supabase's CDN cache for public URLs of replaced files with same name #5737
-
Update: I created a feature request for this. Maybe I'm missing something, but I would like to ask for your solutions for the following problem: I would like to e.g. save avatar images in the storage. In my app, a user can upload an image, which is uploaded to the storage via the Supabase client like so: await supabaseServer.storage
.from("...")
.upload("user-id-123.jpg", avatarFileParsed, {
upsert: true,
contentType: 'image/jpg',
}) This works fine. Looking at the response of a request for a storage image's public URL shows that it is cached via Cloudflare. It also has the cache control set for that (e.g. Some thoughts:
What are your solutions to this problem? My solution to circumvent this problem right now is to create a random ID for the filename on every upload and save that ID for each user in the database. That way, the CDN cannot kick in, but this is obviously far from perfect, if not only for the additional code I had to write. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
2nd seems most common. The Supabase UI uses it the storage tab to view files. Edit: But if you use that for general image access it means you have no cacheing of images at all. |
Beta Was this translation helpful? Give feedback.
-
Well, In that case you can store something as update_time under your DB, (as we prefer to do, when we update anything...right !) |
Beta Was this translation helpful? Give feedback.
-
I also store my file name as the user's uuid. At the end of the filename, I've appended "?updated", like so: |
Beta Was this translation helpful? Give feedback.
Well, In that case you can store something as update_time under your DB, (as we prefer to do, when we update anything...right !)
and use that as a reference under any image url
<Image_url>?t=<update_time>
, that will reduce a lot many hits, and also able to use cached file