ActiveStorage: include an image inside an email or newsletter

By default ActiveStorage generates a URL that points to the Rails application and then redirects to the actual resized image.

The problem is that the URL included in the img tag, inside an email, has an expiration (usually a few minutes). This means that any user that opens the email after some time (e.g. 3 days later) can’t see the images.

What is the correct strategy to use ActiveStorage images inside a marketing email or newsletter? Should I simply set a long expiration like 1 month? Or there is a better solution?

I believe you want the public option or perhaps proxy mode.

1 Like

Proxy mode will still break if your signed_ids change for some reason (which in my experience happens in every new release), so the public option is the best choice if you want to make sure these images will always work.

signed_ids change for some reason (which in my experience happens in every new release)

I believe this was due to the signing algorithm changing with Rails 7. I wouldn’t expect that to happen on every release and when upgrading to Rails 7 I think the old algorithm could have still be kept to preserve the signed ids.

Not saying that change couldn’t have been handled better. It caught many people (including me on one of my apps). But I don’t see that as a guaranteed problem.

It’s happening again for 7.1. The message encryptor is changing from marshal to json, and that changes the signed ids.