I use ActiveStorage with the default Disk service. My api returns the image URL and in the frontend (Vue.js) the image is embedded via an IMG tag. When I open the image URL the image is displayed correctly.
render json: {
image_url: rails_blob_path(user.photo, only_path: true),
....
}
<a :href="image_url">
<img :src="image_url">
</a>
When I look at the source code, Safari keeps trying to call the old URL. This is no longer possible after 5 minutes.
I have tried to set config.active_storage.service_urls_expire_in
directly in the initializer, but this has no effect:
# config/initializers/active_storage.rb
Rails.application.config.active_storage.service_urls_expire_in = 1.week
When I place the image default rails way the image gets a different URL and this is not expire:
image_tag(user.photo)
# => <img src=".../rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSWhjM2w1WlhSbGNtMWxOVEJvWW1kdE1YRm9ObW96TjNvd2IzTjNjd1k2QmtWVU9oQmthWE53YjNOcGRHbHZia2tpYjJsdWJHbHVaVHNnWm1sc1pXNWhiV1U5SW1wdlkzSmZhV052Ymw5amFHRjBYMnB2WTNJdWFHbHNablJmWW14aGRTNXdibWNpT3lCbWFXeGxibUZ0WlNvOVZWUkdMVGduSjJwdlkzSmZhV052Ymw5amFHRjBYMnB2WTNJdWFHbHNablJmWW14aGRTNXdibWNHT3daVU9oRmpiMjUwWlc1MFgzUjVjR1ZKSWc1cGJXRm5aUzl3Ym1jR093WlUiLCJleHAiOiIyMDIwLTA3LTAzVDA5OjQ4OjQyLjc0NFoiLCJwdXIiOiJibG9iX2tleSJ9fQ==--d23e3bb8161f54cce48a3d13a60d906c18574569/user_photo.png" />
rails_blob_path(user.photo, only_path: true)
# => ".../rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBkQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--23e3b6283c346c75d7e6c1e769eacb6d428fec0e/user_photo.png"
Is it possible that I use the URL of the image_tag in the api ?
Ruby version: 2.7.0
Rails version: 6.0.2.2
user.photo.service_url
. It worked for me – 90srebel