【发布时间】:2012-07-29 13:51:56
【问题描述】:
我看到了很多关于这个错误的引用,但没有一个与上传有关,所以我在这里看看其他人是否看到了这个。
我有一个应用程序在 Heroku 的 cedar 堆栈上运行,一切正常,直到我必须上传一个带有 UTF-8 字符的文件,它只是失败并出现以下错误,我不知道发生了什么或为什么会这样, 因为表单主体 是 UTF-8(因为 Rails 强制在所有表单上使用它)。
我有另一个应用程序做几乎相同的事情,但它没有在 Heroku 上运行,它在接收带有 UTF-8 字符的上传文件时工作文件。任何人都知道这可能是什么或我该如何解决?
2012-07-31T17:43:59+00:00 app[web.1]: Started POST "/attachments" for 177.82.145.36 at 2012-07-31 17:43:59 +0000
2012-07-31T17:43:59+00:00 app[web.1]: Processing by AttachmentsController#create as HTML
2012-07-31T17:43:59+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"qhQ8bO/j6WFdu/AGLli6+KrXZPAsFfynwKBN6MqQt9Y=", "attachment"=>{"name"=>"JINGLE CUITÉ", "category_id"=>"8", "city_id"=>"8", "link"=>"", "assets_attributes"=>{"1"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x0000000504d7d8 @original_filename="Tárcio 40.mp3", @content_type="audio/mpeg", @headers="Content-Disposition: form-data; name=\"attachment[assets_attributes][1][file]\"; filename=\"T\xC3\xA1rcio 40.mp3\"\r\nContent-Type: audio/mpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20120731-2-1e58fuf>>}}, "description"=>""}, "commit"=>"Criar arquivo"}
2012-07-31T17:43:59+00:00 app[web.1]: [paperclip] Saving attachments.
2012-07-31T17:43:59+00:00 app[web.1]: [paperclip] saving attachments/2/original_Tárcio_40.mp3
2012-07-31T17:44:00+00:00 app[web.1]: Completed 500 Internal Server Error in 393ms
2012-07-31T17:44:00+00:00 app[web.1]:
2012-07-31T17:44:00+00:00 app[web.1]: app/controllers/crud_controller.rb:20:in `create'
2012-07-31T17:44:00+00:00 app[web.1]: Encoding::CompatibilityError (incompatible character encodings: UTF-8 and ASCII-8BIT):
【问题讨论】:
-
filename=\"T\xC3\xA1rcio 40.mp3\" => 看起来它不喜欢文件名。重命名不带特殊字符是否有效?
-
这只是它被编码以通过网络发送的方式,如果您查看'@original_filename="Tárcio 40.mp3"',您会看到Rails 似乎正确理解了文件名。如果我将其更改为没有特殊字符的名称,则它可以正常工作。
标签: ruby-on-rails ruby file-upload encoding heroku