Rails 4, Paperclip 4.2.1 give error with binary file upload -


i have following setup rails 4 , paperclip 4.2.1

class post< activerecord::base   has_attached_file :key   allowed_content_type = ['text/plain', 'text/rtf',  'text/richtext', 'application/txt', 'application/octet-stream']   validates_attachment_content_type :key, :content_type => allowed_content_type, :message=> "only #{allowed_content_type} allowed" 

i have in application.rb

<body data-controller="<%= controller.controller_path %>" data-action="<%= controller.action_name %>" data-no-turbolink="true">   <%= content_tag "div", id: "params", data: { params: params } %>   <% end %> 

post controller simple

  def update   post.transaction       @post.attributes = (artifact_params)         if @artifact.errors.blank?         redirect_to(@artifact, :notice => 'evidence item updated successfully')       else         render :action => 'edit'         raise activerecord::rollback       end 

it works flawlessly other file types. errors out when try binary file. error:

encoding::undefinedconversionerror in posts#update

app/views/layouts/application.html.erb line #58 raised:

56: <body data-controller="<%= controller.controller_path %>" data-action="<%=  57: controller.action_name %>" data-no-turbolink="true"> 58: <%= content_tag "div", id: "params" , data: { params: params } %> 59: <%#= params.inspect %> 60: <% end %>  

in log says:

actionview::template::error ("\xad" ascii-8bit utf-8):     55: </head>     56:      57: <body data-controller="<%= controller.controller_path %>" data-action="<%= controller.action_name %>" data-no-turbolink="true">     58:   <%= content_tag "div", id: "params" , data: { params: params } %>     59:     <%#= params.inspect %>     60:   <% end %>     61:      app/views/layouts/application.html.erb:58:in `_app_views_layouts_application_html_erb__387563064_102572910'   app/controllers/posts_controller.rb:978:in `block in update'   app/controllers/posts_controller.rb:790:in `update'  rendered /home/adminuser/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (15.0ms)   rendered /home/adminuser/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (7.1ms)   rendered /home/adminuser/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.9ms)   rendered /home/adminuser/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (47.8ms) cannot render console content type multipart/form-dataallowed content types: [#<mime::type:0xa835748 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">, #<mime::type:0xa835608 @synonyms=[], @symbol=:text, @string="text/plain">] 

after spending 1 whole day on this, figured out caused bug in paperclip. if not have binary file mapped application/octet-stream produces error while trying convert params json string in view body. must map binary file type application/octet-stream in order rid of error.

1.so create paperclip.rb in config/initializers/ 2.in config/initializers/paperclip.rb place following code:

paperclip.options[:content_type_mappings] = {   tc: 'application/octet-stream' } 

where tc extension of binary file. don't know how work if have file without extension though. paperclip owners should document save pain users.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -