Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 477355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:34:57+00:00 2026-05-13T00:34:57+00:00

I have an application where we’re having our clients upload a csv file to

  • 0

I have an application where we’re having our clients upload a csv file to our server. We then process and put the data from the csv into our database. We’re running into some issues with char-sets especially when we’re dealing with JSON, in particular some non-converted UTF-8 characters are breaking IE on JSON responses.

Is there a way to convert the uploaded csv file to UTF-8 before we start processing it? Is there a way to determine the character encoding of an uploaded file? I’ve played with iconv a bit but we’re not always sure what encoding the uploaded file will have. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:34:58+00:00Added an answer on May 13, 2026 at 12:34 am

    This solution might be not ideal, but should do the job.

    First, the ingredients:

    • chardet (sudo gem install chardet)
    • fastercsv (sudo gem install
      fastercsv
      )

    Now the actual code (not tested):

    require 'rubygems'
    require 'UniversalDetector'
    require 'fastercsv'
    require 'iconv'
    
    file_to_import = File.open("path/to/your.csv")
    # determine the encoding based on the first 100 characters
    chardet = UniversalDetector::chardet(file_to_import.read[0..100])
    if chardet['confidence'] > 0.7
      charset = chardet['encoding']
    else 
      raise 'You better check this file manually.'
    end
    file_to_import.each_line do |l| 
      converted_line = Iconv.conv('utf-8', charset, l)
      row = FasterCSV.parse(converted_line)[0]
      # do the business here
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have application that runs non stop in the background on a dedicated remote
Let say I have application menus in a database with their icon images (binary
I am busy converting a web application to MVC and have some information saved
My application I have an application design that looks like this: web application layer
I have an application, it is creating an ICS similar to the following: BEGIN:VCALENDAR
I have an application I have already started working with and it seems I
I have a WinForms application. That application have a rich functionality. It can create
I have an application that I'm developing in Visual Studio 2010 that utilizes a
I have an application which is written in VC++ using VC 6.0 version. Now
I have a class library I want to unit test using Microsofts unit test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.