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

Make content_type_mappings option more user-friendly #43

Closed
svyatov opened this issue Dec 8, 2020 · 1 comment · Fixed by #119
Closed

Make content_type_mappings option more user-friendly #43

svyatov opened this issue Dec 8, 2020 · 1 comment · Fixed by #119

Comments

@svyatov
Copy link

svyatov commented Dec 8, 2020

Is your feature request related to a problem? Please describe.
I spent quite some time debugging an issue in our project due to misconfiguration of content_type_mappings - keys were strings instead of symbols.

Describe the solution you'd like
I'd like for content_type_mappings option to be more user-friendly and/or fool-proof. Two options here:

  1. Raise an error when there are string keys provided;
  2. Don't raise any errors and make this option a "hash with indifferent access".

Additional context
This issue was discovered when we tried to upload .json files. Linux file utility returns text/plain content type while content type from extension is application/json. So in order to fix this we had to add a custom mapping:

Paperclip.options[:content_type_mappings] = {
  'json' => 'text/plain'
}

The above code didn't work, because the key is a string, not a symbol. The following code works as expected:

Paperclip.options[:content_type_mappings] = {
  json: 'text/plain'
}

This happens because of this code:

def filename_extension
File.extname(@name.to_s.downcase).sub(/^\./, "").to_sym
end

There was a related issue in the original repo: thoughtbot#2425

I'm happy to provide a PR once we settle on the exact solution: raise or accept both strings and symbols. Plus we could fix the case-sensitivity issue mentioned above as well.

@ssinghi
Copy link

ssinghi commented Dec 11, 2020

Thank you @svyatov!
I think the code should support both strings and symbols, please create a PR for this. Thanks!

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