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 7797923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:50:37+00:00 2026-06-01T23:50:37+00:00

I have a file which is uploaded via a regular form_for , this gives

  • 0

I have a file which is uploaded via a regular form_for, this gives me a ActionDispatch::Http::UploadedFile object in the params hash on which I can call .read to get the content. I now need to embed the file in an XML document. I’m using a regular Ruby string for now to construct the XML. The default encoding for a Rails string is utf-8.

Therefore I get the error Encoding::UndefinedConversionError, "\x89" from ASCII-8BIT to UTF-8.

This happens for the following files:

what-matters-now-1.pdf: application/octet-stream; charset=binary
example.csv: text/plain; charset=utf-8
investigations.png: image/png; charset=binary

It does not happen for:

my_test.txt: text/plain; charset=us-ascii

I have tried changing the encoding, but I get the same error:

params[:file].read.encode('utf-8')
  • 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-06-01T23:50:39+00:00Added an answer on June 1, 2026 at 11:50 pm

    First, you cannot embed a binary file in an XML document without some sort of conversion to text. At least the PDF document and the PNG image need to be encoded somehow – probably Base64 – before you start trying to treat their contents as strings of characters instead of sequences of bytes.

    The UndefinedConversionError indicates that you’re trying to convert text into UTF-8 from what Ruby thinks is ASCII. But the source text includes a byte whose value is 0x89 (137 decimal), which is outside the ASCII range. That is not at all unexpected if the source file is a binary file, and base64-encoding it will fix that problem.

    If, however, the source file generating that error is already text, then you need to determine and specify what character set it is actually using. The 0x89 indicates it is neither ASCII nor UTF-8, so the most likely options are Latin-1 or Windows-1252.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl script which will allow for a file to be uploaded
I have this file which I need to read the first bytes to check
In my project I have a file uploading feature. Files are uploaded via FTP.
I have an system with which users can upload a CSV file via an
I have a file which has multiple columns, whitespace separated. e.g: data1 data2 data3
I have .zip file which contain csv data. I am reading .zip file using
i have a file which contains a lot of update query and some other
I have a file which is combination of PHP and HTML. How can i
I have a file which may be in ASCII or UTF-8 format. I can
I have a file which i'm parsing out myself. Every time i spot a

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.