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

Tempfile and @content_type assignment #1487

Closed
Rendez opened this issue Oct 29, 2014 · 2 comments
Closed

Tempfile and @content_type assignment #1487

Rendez opened this issue Oct 29, 2014 · 2 comments

Comments

@Rendez
Copy link

Rendez commented Oct 29, 2014

Hi,

I would like to open the conversation on a closed issue for a new angle of discussion #284 :

My app am using Rack::Multipart module, as part of a Sinatra-based app (Padrino TBS). As processed by the Multipart parser: https://github.com/rack/rack/blob/master/lib/rack/multipart/parser.rb#L226 we obtain a Hash containing :type, instead of :content_type. This is fine Rack behavior, but it messes completely with the way Carrierwave decides to assign a content_type to a file, when an instance of SanitizedFile is created: https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/sanitized_file.rb#L287

This causes the assignment of content_type to result in value "" or nil, depending (empty in any case).

Plus when later the cached file is read, SanitizedFile tries to determine the content_type via the Mime Type Gem, traditionally a name of a cached file in FS does not contain the extension anymore, as to the Tempfile instance Rack creates. What this causes is that storing the upload via FOG (aws in my case) would not send any content-type headers, and AWS does not recognize for example SVG files automatically. They are uploaded, but not delivered later with the right Content-Type (image/svg+xml) header but rather text/plain.

I've resorted to adding :content_type to the hash prior to creating my ActiveRecord instance

    params[:file][:content_type] = params[:file][:type]
    @upload = Upload.new(file: params[:file])

Which solves the issue, but as I don't have a lot of expertise with Carrierwave, I would like to throw the first stone to propose what would be the best way to address this issue involving Rack Multipart, Carrierwave's caching-first strategy, and AWS content_type setting.

@bensie bensie closed this as completed in cb278d7 Nov 19, 2014
@bensie
Copy link
Member

bensie commented Nov 19, 2014

Fixed! Please give master a try and report back if you still see this issue.

@Rendez
Copy link
Author

Rendez commented Nov 19, 2014

@bensie works! Thanks a lot.

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