hooks plugin allows you to trigger some code around
processing/storing/deleting of each file.
Shrine uses instance methods for hooks. To define a hook for an uploader, you just add an instance method to the uploader:
class ImageUploader < Shrine def around_process(io, context) super rescue ExceptionNotifier.processing_failed(io, context) end end
Each hook will be called with 2 arguments,
context. You should always call
overriding a hook, as other plugins may be using hooks internally, and
super those wouldn't get executed.
Shrine calls hooks in the following order when uploading a file:
Shrine calls hooks in the following order when deleting a file:
By default every
around_* hook returns the result of the
class ImageUploader < Shrine def around_store(io, context) result = super result.class #=> Shrine::UploadedFile result # it's good to always return the result for consistent behaviour end end