Unable to set Host in Shrine::Storage::FileSystem

Brief Description

We have two environments:

  • demo that uses storage/file_system
  • production that uses storage/s3

And so, we have single code user.avatar_url in both environments of our API that responds with different format of url.

Expected behavior

  • production S3:

  • demo file system:

Actual behavior

  • production S3:

  • demo file system:

There is also parameter that should help us but actually can broke the production because of S3 usage:
user.avatar_url(host: Rails.application.routes.default_url_options[:host]) and need to be passed in all places we are use avatar_url what is really looks sad…


Need to add attr host into Shrine::Storage::FileSystem that will be used before prefix and return full form of url if we need it.

Could you post a self-contained script that reproduces the problem? You can use a template from here.


You’re not passing the :host option to file URLs (only to default_url plugin, which is only applied to the default URL). How is it “unexpected” that file URLs don’t have the URL host, if you’ve not told Shrine to use one?

You probably want to use the url_options plugin to pass the :host option to file URLs:

Shrine.plugin :url_options,
  cache: { host: "" },
  thumbs: { host: "" },
  store: { host: "" }

Sorry, I tried to provide the most suitable topic. And it says that actually API goes in unexpected way and I wanted to ask how I can handle it. Your answer should work for me and I thank you for that. But why I was not able to find it in the docs?


The most near thing was there And it says to use #url with host option in all places.

The actual bug was in the point that I didn’t have the way to “tell” shrine local storage what is my host :slight_smile: