Home > other >  Rails 6 - ActiveStorage 404 not found after sometime
Rails 6 - ActiveStorage 404 not found after sometime

Time:05-30

Everything works ok for X days but then, something crash for random photos ...

In VIEW I display images like this:

<%= link_to image_tag(f.image_2.variant(resize_to_fill: [30,30]), 
    :alt => 'x abc'   f.username.to_s, loading: "lazy" ),
    f.image_2.variant(resize_to_limit: [800,600]),
    :class=>'large_photo_box fancybox' 
 %> 

Class has:

 has_one_attached :image_1
 has_one_attached :image_2
 has_one_attached :image_3

Production.rb:

config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true

config.cache_store = :file_store, "/tmp/my_cache"
config.public_file_server.headers = {
  'Cache-Control' => "public, max-age=#{10.days.to_i}"
}

It works, but ... after X days the photo stops showing and the no photo icon for the viewer is placed.

When it works:

  • when I copy URL for image in new tab - images display
  • when I open chrome development tools ( CTRL SHIFT J ) and reload page - the photos display again

What is going on? is there any RoR programmer left in here? ;)

I do not calculate days but maybe problem is in production.rb cache ?

EXAMPLE OF 404 NOT FOUND URL:

https://example.com/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDVG9JYTJWNVNTSWhNbVpzTkdObE1qWjRNRGRxYmpobmNqWnZZakYzY2podFpXSnZad1k2QmtWVU9oQmthWE53YjNOcGRHbHZia2tpUzJsdWJHbHVaVHNnWm1sc1pXNWhiV1U5SWpJMk1UZ3dOemxmTXpneFlpNXFjR2NpT3lCbWFXeGxibUZ0WlNvOVZWUkdMVGduSnpJMk1UZ3dOemxmTXpneFlpNXFjR2NHT3daVU9oRmpiMjUwWlc1MFgzUjVjR1ZKSWc5cGJXRm5aUzlxY0dWbkJqc0dWRG9SYzJWeWRtbGpaVjl1WVcxbE9ncHNiMk5oYkE9PSIsImV4cCI6IjIwMjItMDUtMjhUMDc6MzQ6MzEuNzA2WiIsInB1ciI6ImJsb2Jfa2V5In19--566629b24793a7cca81a263eeb917ecd0d616e72/2618079_381b.jpg

CodePudding user response:

If you want permanent url for your variants, add public: true for your service in config/storage.yml. More here

CodePudding user response:

I think that this is solution:

"To generate a permanent URL for a blob, you can pass the blob to the url_for view helper. This generates a URL with the blob's signed_id that is routed to the blob's RedirectController"

Will see in few days if there isn't any errors.

  • Related