Maurício Linhares
Maurício Linhares

Reputation: 40333

Encoding::CompatibilityError (incompatible character encodings: UTF-8 and ASCII-8BIT) - when uploading files to Heroku

I've seen a lot of references to this error, but none of them is related to uploads, so here I am on SO to see if someone else has seen this.

I have an application running on Heroku's cedar stack and everything goes fine until I have to upload a file with UTF-8 characters on it, it just fails with the error below and I have no idea what's happening or why that, since the form body is UTF-8 (as Rails forces it on all forms).

I have another app that does almost the same thing but that isn't running on Heroku that works file when receiving uploads with UTF-8 characters. Anyone has any idea what this could be or how I could fix it?

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):

Upvotes: 2

Views: 2073

Answers (1)

Anthony Alberto
Anthony Alberto

Reputation: 10405

Sounds like a bug with paperclip : https://github.com/thoughtbot/paperclip/issues/301.

Upgrading to latest version should fix it, according to the comments

Upvotes: 1

Related Questions