3
votes

2.2 and raisl 4.1. I tried to read an xlsx file from user.

<%= form_for(@attachment, :html => { :multipart => true,:class => 'form-horizontal' }) do |f| %>
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">List of Company Name</label>
    <div class="col-sm-10">
        <%= f.file_field :attachment,class: 'form-control' %>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <%= f.submit 'Import Company Name list',:class => "btn btn-primary" %>
    </div>
  </div>
<% end %>

In console

 Parameters: {"utf8"=>"✓", "authenticity_token"=>"BJMhP6MnjUH17esTRxtaViIpBXL/aMzQgzuOI0a9LjI=", "attachment"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x00000006cd25e8 @tempfile=#<Tempfile:/tmp/RackMultipart20150701-9558-59shsp>, @original_filename="Book2.xlsx", @content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", @headers="Content-Disposition: form-data; name=\"attachment[attachment]\"; filename=\"Book2.xlsx\"\r\nContent-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n">}, "commit"=>"Import Company Name list"}

Even though the parameter passing with UTF-8 mark I'm getting

Encoding::UndefinedConversionError - "\xA0" from ASCII-8BIT to UTF-8:

error.. Tried varied solution like .force_encoding('UTF-8') mime::type but nothing worked out?

Have anyone has an idea about this issue?

1

1 Answers

1
votes

I found the reason why this happen , I have the following

gem 'meta_request','0.2.1'

in my gemfile and removing this gem make the file upload works perfect.

hope this will help someone else...