Skip to content

Storage download (storage.from.download url) is cached in the CDN even for deleted file #116

Description

@GaryAustin1

Bug report

It is desirable to cache image and some file urls.
The storage download function though seems more like a database call to get the file data from the database/storage system.
A deleted file from storage (no object and data) will still download when called with supabase.storage download.
Cache busting with ?bust=123 in the path provided to download does return 404.
The download url does not appear to be cached in the browser, using a 2nd browser will still return a file even though deleted and never used on the browser.
After 1 hour the download function does get a 404 error.

To Reproduce

Create a file in the UI in a private bucket.
Download it with:

  .storage
  .from('avatars')
  .download('folder/avatar1.png')

Delete the file.
Run the download code on any browser and file still downloads.

Expected behavior

This behavior should at least be documented as it is not clear download is cached by it appears just the CDN.
Or download should not be cached at all as it is more like a database call then a url for an image.

Screenshots

System information

Latest Supabase instance and supabase.js code.

Additional context

Activity

  1. changed the title [-]Storage download (storage.from.download) is cached in the CDN even for deleted file[/-] [+]Storage download (storage.from.download url) is cached in the CDN even for deleted file[/+] on Mar 4, 2022
  2. mousindev commented on Apr 7, 2022

    @mousindev

    Hi,

    we face the same issue but in a different use case. We store expense tickets under the user folder being the name of the file the id of the expense. If for any reason the ticket gets replaced with a new image, the name of the file will be exactly the same expense_id.jpeg, so due to that cache of Supabase, when trying to access the preview of the ticke through the storage.from().download() method, it will still show the previous one.

    Is there any workaround for this in the meantime it gets fixed?

    Thanks

  3. GaryAustin1 commented on Apr 7, 2022

    @GaryAustin1
    Author

    You need to do the cache busting string added at end with time.
    ?bust=95857573738 for now.

  4. mousindev commented on Apr 7, 2022

    @mousindev

    Hi @GaryAustin1, thanks for the answer. So, if I understand correctly, you mean to append it to the path like below being the number the current timestamp?

    this.supabase.storage
    .from('avatars')
    .download('folder/avatar1.png?bust=current_timestamp')
  5. GaryAustin1 commented on Apr 7, 2022

    @GaryAustin1
    Author

    That should work, pretty sure based on my submit that is what I did. The browser and CDN will think it is a new file. I would only use it though when you know you need immediate feedback as if you do that everywhere you will never cache images, etc.

  6. mousindev commented on Apr 7, 2022

    @mousindev

    Thanks @GaryAustin1. I just did the changes and seems to work. In this specific scenario, it is ok for me to not cache it as it is very unusual to replace a scan. Thanks!

  7. rahul3v commented on Apr 12, 2022

    @rahul3v
    Contributor

    Well, In that case you can store something as update_time under your Database, (as we prefer to do, when we update anything...right !), and use that as a reference under any image url (let say <Image_url>?t=<update_time>), that will reduce a lot many hits, and also able to use cached file

  8. fenos commented on Sep 28, 2022

    @fenos
    Contributor

    Closing as the current solution is to use a query string parameter to bust the cache.
    We'll make more improvements and automating the cache busting in the near future #120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions