Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using :url_options alongside :default_storage and :dynamic_storage does not work as expected #687

Open
camiloforero opened this issue May 16, 2024 · 0 comments

Comments

@camiloforero
Copy link

camiloforero commented May 16, 2024

Hi

Checking out the :url_options plugin, I noticed that if I declare something very straightforward like plugin :url_options, store: { expires_in: 60 * 60 * 24 }, this value gets stored at shrine_class.opts[:url_options][:store], so this line will later retrieve and merge these url options whenever the current storage_key is :store

However, let's assume I am also using the :dynamic_storage and :default_storage plugins, like this:

plugin :default_storage, store: -> {
  :"#{record.subdomain}_store"
}

plugin :dynamic_storage
storage /(\w+)_store/ do |match|
Shrine::Storage::S3.new(
    prefix: match[1],
    # Storage config
  )
end

In this case, the :url_options plugin no longer works properly, because the value of storage_key inside the shrine file context is not :store, but whichever value was dynamically generated (something like :mysubdomain_store.

As an idea for a solution, I tried to find a way to check whether the current storage_key equals the Attacher's :store_key or :cache_key, but I couldn't find a good way to reach the Attacher from inside the UploadedFile instance. Maybe you have a better idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant