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

Wrong data format for automatic detection. .aiinstead of .pdf #77

Closed
brunto opened this issue Oct 21, 2019 · 3 comments
Closed

Wrong data format for automatic detection. .aiinstead of .pdf #77

brunto opened this issue Oct 21, 2019 · 3 comments

Comments

@brunto
Copy link

brunto commented Oct 21, 2019

When I submit a PDF file base64 encoded like this data:application/pdf;base64,JVBERi0xLjQKJfjl0MTGCjEgMCBvYmoKPDwgL........... the automatic detection change the extension from .pdf to .ai.

I use:

gem 'carrierwave', '~> 1.3.1'
gem 'carrierwave-base64', '~> 2.8.0'

Here is my code:

    file = params[:attachment][:file]
    @attachment = Attachment.new(attachment_params)
    file = file.gsub('data:application/octet-stream;base64', "data:#{@attachment.mime_type};base64")
    @attachment.attached_file = file
    @attachment.save

ps: When I submit an image base64 everything works fine.

Any idea?

@brunto
Copy link
Author

brunto commented Oct 21, 2019

I found this:

MIME::Types['data:application/pdf'].last.preferred_extension
=> "ai"

@brunto
Copy link
Author

brunto commented Oct 21, 2019

See: mime-types/ruby-mime-types#143

@halostatue
Copy link

This is not a bug in mime-types, but in mime-types-data. Update that gem to 3.2019.1009 and the issue will fix itself. Resolved in mime-types/mime-types-data#24.

@brunto brunto closed this as completed Oct 21, 2019
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