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

Absolute cache_dir breaks url #2063

Closed
jughead opened this issue Nov 3, 2016 · 1 comment
Closed

Absolute cache_dir breaks url #2063

jughead opened this issue Nov 3, 2016 · 1 comment

Comments

@jughead
Copy link

jughead commented Nov 3, 2016

I currently use carrierwave 0.11.2 with fog, asset_host, and absolute cache_dir:

CarrierWave.configure do |config|
  if Rails.env.test?
    config.storage = :file
  else
    config.storage = :fog
    config.fog_directory = Rails.application.secrets.s3_bucket
    config.fog_credentials = {
        provider: 'AWS',
        aws_access_key_id: Rails.application.secrets.s3_key,
        aws_secret_access_key: Rails.application.secrets.s3_secret,
        region: Rails.application.secrets.s3_region,
    }
    config.asset_host = Rails.application.secrets.amazon_cloudfront_domain
  end

  config.cache_dir = "#{Rails.root}/tmp/uploads" # To let CarrierWave work on heroku
  config.remove_previously_stored_files_after_update = false
end

Now let's see CarrierWave::Uploader::Url.
Let's imagine I have a model with a simple uploader. When the image gets uploaded the model uploader initializes cached SanitizedFile. So the path to the file is /path/to/project/tmp/uploads/bla/bla/bla/filename.jpg. According to the trimming root path code and the asset host set, the url becomes: https://<domain>/path/to/project/tmp/uploads/bla/bla/bla/filename.jpg. And this is incorrect.
I don't know the correct way to fix this. If we don't want to return url for cached/non-stored file I would raise an exception rather than return the incorrect url.

@jughead jughead changed the title Absolute cached_dir breaks url Absolute cache_dir breaks url Nov 3, 2016
@mshibuya
Copy link
Member

mshibuya commented Nov 5, 2016

To serve cached files, they must be placed in publicly accessible directory. But you're using Heroku, so you don't have write access to {Rails.root}/public directory.

This is the case that cache storage feature is trying to solve, see the PR for usage:
#1312
(note: this feature is not included in 0.11 releases, please use 1.0.0.rc or the master branch)

@mshibuya mshibuya closed this as completed Nov 5, 2016
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

2 participants