# Encoding issue with file upload

**URL:** <https://www.ruby-forum.com/t/encoding-issue-with-file-upload/174158>\
**Category:** Rails\
**Created:** [August 21, 2009, 1:51pm UTC](https://www.ruby-forum.com/t/encoding-issue-with-file-upload/174158 "2009-08-21T13:51:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![akyrho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@akyrho](https://www.ruby-forum.com/u/akyrho)\
**Post date:** [August 21, 2009, 1:51pm UTC](https://www.ruby-forum.com/t/encoding-issue-with-file-upload/174158/1 "2009-08-21T13:51:49Z")

</div>

Hello,

I’ve got some issue while trying to upload and read csv file on my  
application. For some file, i get some odd character appearing when i  
print the result, but not in my logs. Here joined a screen to explain  
what i’m talking about.

I think it’s an encoding issue, so I tried to convert file content in  
UTF-8 with Iconv, but i get some trouble to determine the exact original  
encoding.

Any help would be appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![akyrho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@akyrho](https://www.ruby-forum.com/u/akyrho)\
**Post date:** [August 21, 2009, 4:23pm UTC](https://www.ruby-forum.com/t/encoding-issue-with-file-upload/174158/2 "2009-08-21T16:23:00Z")

</div>

CÃ©d B. wrote:

> Hello,
> 
> I’ve got some issue while trying to upload and read csv file on my  
> application. For some file, i get some odd character appearing when i  
> print the result, but not in my logs. Here joined a screen to explain  
> what i’m talking about.
> 
> I think it’s an encoding issue, so I tried to convert file content in  
> UTF-8 with Iconv, but i get some trouble to determine the exact original  
> encoding.
> 
> Any help would be appreciated.
> 
> Thanks

that’s an encoding issue with &nbsp; spaces.

---

<div class="post-metadata">

**Author:** ![akyrho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@akyrho](https://www.ruby-forum.com/u/akyrho)\
**Post date:** [August 21, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/encoding-issue-with-file-upload/174158/3 "2009-08-21T16:25:24Z")

</div>

> that’s an encoding issue with &nbsp; spaces.

As a follow-up, it could also be due to a BOM (byte order mark) issue.

---

<div class="post-metadata">

**Author:** ![akyrho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@akyrho](https://www.ruby-forum.com/u/akyrho)\
**Post date:** [August 24, 2009, 9:13am UTC](https://www.ruby-forum.com/t/encoding-issue-with-file-upload/174158/4 "2009-08-24T09:13:26Z")

</div>

Thank you for answers. Is there an easy way to clean up my file before  
parsing it?

---

<div class="post-metadata">

**Author:** ![akyrho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@akyrho](https://www.ruby-forum.com/u/akyrho)\
**Post date:** [August 26, 2009, 5:11pm UTC](https://www.ruby-forum.com/t/encoding-issue-with-file-upload/174158/5 "2009-08-26T17:11:19Z")

</div>

Ok, i found a fix for this, using Iconv lib, and it seems to work  
correcty.

But i still get an issue with accented character. If i get a surname  
with accented character, like “CÃ©dric”, Iconv returns me “C’edric”. I’ve  
got similar problems with every accented character.

I read somewhere that i had to set $KCODE = ‘utf8’, but it didn’t do the  
trick. And i really need those accented character, so i can’t convert  
them into their similar letters (ie.: [Ã©Ã¨ÃªÃ«]Â =\> e)

Thanks per advance.
