Global prerocessor for ActiveStorage

Today I want to tell you how to do global preprocessing of uploaded files in ActiveStorage. Unfortunately ActiveStorage design doesn’t provide this feature out of the box, or I haven’t found any information about it. But sometimes you may need to process attachments for all models in a project. To achieve this goal, we need to override several methods of singleton class of ActiveStorage::Blob class, in my version (rails 6.1) they are build_after_upload, build_after_unfurling and upload....

June 2, 2024 · 2 min