Active Storage attachments could not be found after changing server

I moved my site to a new server and the whole migration excluding ActiveStorage was successful.

now I can upload new attachments / images but older ones will not be displayed. what could be the reason? the storage folder and database tables of ActiveStorage were both fully migrated.

does anybody have ideas or experiences?

Have you confirmed that the old attachments are under the same directory structure as the new ones? And that the ownership and permissions for the old attachments will allow the Rails server process(es) to read the files?

yes. same structure. same (needed) permissions.

I remember running into this myself, and am racking my brain to remember the fix.

One more easy thing to try:

  • rake assets:precompile (Rails 5) or rails assets:precompile (Rails 6+)
  • touch tmp/restart.txt

Same issue. It doesn’t work …

There are no changes than the hardware and os version…

Same domain, same gems, same config…

How exactly does this error manifest? Ruby/Rails Exception? HTTP 404? Silent failure?

What’s in the logs when you attempt to access one of the migrated ActiveStorage files?

I click on the “image” and choice “open image in new tab”

Now a tap opens and a empty file (0KB) will Be downloaded. The file has the right name of the origin file. But it’s empty and damaged.

Anything noteworthy in the log files for Rails and your web server?

Come to think of it, I’d also recommend checking your web server site config file. Make sure it’s identical, or very nearly so, on both the old and new systems.

Started GET “/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDVG9JYTJWNVNTSWhZVEUxTm10dGN6ZGpkR2N4Wkhoelkza3lkVFpoZW1veWNHVjVZd1k2QmtWVU9oQmthWE53YjNOcGRHbHZia2tpV1dsdWJHbHVaVHNnWm1sc1pXNWhiV1U5SWxKa1pXeFRNalZmTVRBNE1IZ3hNRGd3Y0hndVVFNUhJanNnWm1sc1pXNWhiV1VxUFZWVVJpMDRKeWRTWkdWc1V6STFYekV3T0RCNE1UQTRNSEI0TGxCT1J3WTdCbFE2RVdOdmJuUmxiblJmZEhsd1pVa2lEbWx0WVdkbEwzQnVad1k3QmxRNkVYTmxjblpwWTJWZmJtRnRaVG9LYkc5allXdz0iLCJleHAiOiIyMDI0LTA5LTEyVDIwOjUwOjQyLjA2NloiLCJwdXIiOiJibG9iX2tleSJ9fQ==–64dbe3814aeb95983874748820bd6edb58c4dee8/RdelS25_1080x1080px.PNG” for xxx.xxx.xxx.xxx at 2024-09-12 22:45:42 +0200

Cannot render console from xxx.xxx.xxx.xxx! Allowed networks: 127.0.0.0/127.255.255.255, ::1

Processing by ActiveStorage::DiskController#show as /

Parameters: {“encoded_key”=>“[FILTERED]”, “filename”=>“RdelS25_1080x1080px”}

Completed 304 Not Modified in 1ms (ActiveRecord: 0.0ms | Allocations: 179)

That Completed 304 log entry indicates that the server believes that your browser already has a cached copy of the image. So clear the browser cache and reload the image. (Low probability, but easy to try!)

There was something like this previously where attachments are lost when upgrading rails version.

Related to secret keys changing…