【发布时间】:2015-09-18 14:33:49
【问题描述】:
2.2 和 raisl 4.1。我试图从用户那里读取一个 xlsx 文件。
<%= 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 %>
在控制台中
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"}
即使参数以 UTF-8 标记传递,我也得到了
Encoding::UndefinedConversionError - "\xA0" from ASCII-8BIT to UTF-8:
error.. 尝试了不同的解决方案,例如 .force_encoding('UTF-8') mime::type 但没有成功?
有人知道这个问题吗?
【问题讨论】:
标签: ruby-on-rails ruby file-upload encoding utf-8