ruby-on-rails – Erro: incompatible character encodings: UTF-8 and ASCII-8BIT


Incompatible character encodings: UTF-8 and ASCII-8BIT.

"post"=>{"title"=>"Somos apaixonados por música!",
"caption"=>"Estamos entrando na fase final da construção do estúdio. Mau podemos esperar para iniciar os trabalhos dos grandes artistas que nos esperam.",
"photo"=>#<ActionDispatch::Http::UploadedFile:0x00000103339718 @original_filename="Captura de Tela 2014-05-30 a\xCC\x80s 11.45.37 (2).png",
@headers="Content-Disposition: form-data; name=\"post[photo]\"; filename=\"Captura de Tela 2014-05-30 a\xCC\x80s 11.45.37 (2).png\"\r\nContent-Type: image/png\r\n",
"commit"=>"Cadastrar Notícia"}


The problem is in the name of the file I'm trying to upload, it contains an accent ( Screen Capture 2014-05-30 at 11.45.37 (2).png ) and then it is generating this error.

Is there any way to resolve this?


Try the following:

file_data = params[:import_file]"ISO-8859-1")
utf8_file_data = file_data.encode(utf8_format)

Taken from this Stack-EN question

Scroll to Top