From: duerst@... Date: 2017-07-12T10:29:01+00:00 Subject: [ruby-core:82009] [Ruby trunk Bug#13738] Active Scaffold image upload using CarrierWave gem Issue #13738 has been updated by duerst (Martin D��rst). karanamsandhya (Karanam Sandhya) wrote: > getting Encoding::UndefinedConversionError ("\xFF" from ASCII-8BIT to UTF-8): this error while uploding the image. There's definitely no error in Ruby itself, in the encoding "ASCII-8BIT", only the lower half is convertible; the upper half is okay in the source, but undefined and so not convertible to any other encoding. I don't know the CarrierWave gem. But if they are trying to convert image data (which very easily can contain a 0xFF byte, and for which a String with an encoding of ASCII-8BIT (alias: BINARY) is appropriate) to UTF-8, then they are definitely making a mistake. If the error happens for some other data (e.g. for some text data extracted from an image header), then I can understand that such an error happens. If the image format actually defines what encoding to use for the text, then String#force_encoding should be applied first. If not, I'd suggest to change the conversion from something like ``` string_with_unknown_encoding_labeled_as_ascii_8bit.encode('UTF-8') ``` to something like ``` string_with_unknown_encoding_labeled_as_ascii_8bit.encode('UTF-8', invalid: :replace) ``` which will convert 0xFF bytes (and similar) to '?'. ---------------------------------------- Bug #13738: Active Scaffold image upload using CarrierWave gem https://bugs.ruby-lang.org/issues/13738#change-65740 * Author: karanamsandhya (Karanam Sandhya) * Status: Third Party's Issue * Priority: Normal * Assignee: * Target version: * ruby -v: 2.3.1 * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- getting Encoding::UndefinedConversionError ("\xFF" from ASCII-8BIT to UTF-8): this error while uploding the image. and image params are like this: "photo"=>#, @original_filename="1.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"record[photo]\"; filename=\"1.jpg\"\r\nContent-Type: image/jpeg\r\n"> -- https://bugs.ruby-lang.org/ Unsubscribe: