1

I'm writing a Rails app that allows the user to upload TSV (Tab-separated values) files to be parsed on the server. Those files are encoded in UTF-16. All goes fine in local, but when I try to open the file with such encoding on Heroku, I'm getting a warning that says warning: Unsupported encoding utf-16 ignored. When later I try to read such file, it obviously fails stating invalid byte sequence in UTF-8. See an excerpt of the code below:

    File.open(params[:batch_import][:file].path, 'r:utf-16') do |f|
      @recipients = Recipient.from_tsv(f.read)
    end

Is there any walkaround that I can do?

4

1 に答える 1

0

UTF-16ファイルはモードで開く必要がありbinaryます。これを試して:

File.open(params[:batch_import][:file].path, 'rb:utf-16') do |f|
  @recipients = Recipient.from_tsv(f.read)
end
于 2013-02-26T20:21:27.537 に答える