简体   繁体   中英

rails paperclip image upload Encoding::UndefinedConversionError (“\xFF” from ASCII-8BIT to UTF-8):

I have used paperclip for image storage and when I try to upload and save the image, image it getting saved but I am getting Encoding::UndefinedConversionError while redirecting to other page.

I tried to remove the paperclip code and do the same with normal file upload mechanism, but result is the same.

Parameters: {"utf8"=>"✓", "authenticity_token"=>"janP4YndP+9xORuxP5BkEuRFpVZi7GvLcs3u+6RsSfs=", "user"=>{"profile_picture"=>#ActionDispatch::Http::UploadedFile:0x3622916a @original_filename="36.jpg", @headers="Content-Disposition: form-data; name=\"user[profile_picture]\"; filename=\"36.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/home/ROOT/RackMultipart.13883.61589>, @content_type="image/jpeg">}}


Command :: file -b --mime 
 '/home/ROOT/36130617-13883-1gqm197-61590130617-13883-1uub191-61593'
(1.0ms)  UPDATE `users` SET `avatar_file_name` = '36.jpg', `avatar_file_size` = 107409, `avatar_updated_at` = '2013-06-17 13:44:04', `updated_at` = '2013-06-17 13:44:04' WHERE `users`.`id` = 10
 [paperclip] deleting /home/ROOT/public/system/users/avatars/000/000/010/original/123.jpg
 [paperclip] deleting /home/ROOT/public/system/users/avatars/000/000/010/medium/123.jpg
 [paperclip] deleting /home/ROOT/public/system/users/avatars/000/000/010/thumb/123.jpg
Redirected to url


Encoding::UndefinedConversionError - "\xFF" from ASCII-8BIT to UTF-8:
  org/jruby/RubyString.java:7580:in `encode'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:123:in `escape'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:69:in `escape'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:171:in `encode_json'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:214:in `encode_json'
  org/jruby/RubyArray.java:2361:in `map'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:214:in `encode_json'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:48:in `encode'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:46:in `encode'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:246:in `encode_json'
  org/jruby/RubyHash.java:1257:in `each'
  org/jruby/RubyEnumerable.java:718:in `map'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:246:in `encode_json'
  (gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:48:in `

I checked with the paperclip gem and it uses binmode for opening the file.

Removed support for the encode_json hook used for encoding custom objects into JSON. This feature has been extracted into the activesupport-json_encoder gem.

Add activesupport-json_encoder gem to Gemfile fix this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM