How to access record in upload_options when using mirroring plugin

With the upload_options plugin it is possible to set upload options based on the record. For example, setting S3 acl like so:

plugin :upload_options, store: -> (io, derivative: nil, **options) do
  record = options[:record]
  if !record.confidential? && record.published?
    { acl: "public-read" }
    { acl: "private" }

But when using the the mirroring plugin, **options does not contain the record. When I have

Shrine.plugin :mirroring, mirror: { store: :s3_store }


plugin :upload_options, s3_store: -> (io, derivative: nil, **options) do
  # as above

then options looks like this:

{ :location=>"...", :close=>false, :action=>:mirror, :metadata=>{ }}

Is there a way to get acces to the record here?

At the moment I’m afraid not, because mirroring works on the uploader level and not the attacher level, and thus doesn’t have access to the record.

We should probably be able to pass parameters forwarded to main Shrine#upload (which do include the record information) into UploadedFile#mirror_upload and into the Shrine#upload call inside.

Okay, thanks for your reply. Will have a look to see how that could be implemented. If I find out how to do that in a nice way, I’ll create a pull request.

With this modification I can pass options around for mirror uploads:

I have the impression that this is not every elegant though, and probably not very well aligned with the overall architecture of shrine.

This is actually exactly the kind of solution I had in mind, thanks for coming up with it. Would you like to send a pull request?

Okay, sure! Done that a minute ago.