1

我使用回形针进行图像存储,当我尝试上传和保存图像时,图像被保存,但我Encoding::UndefinedConversionError在重定向到其他页面时得到。

我试图删除回形针代码并使用正常的文件上传机制执行相同的操作,但结果是相同的。

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 `

我检查了回形针 gem,它使用 binmode 打开文件。

4

1 回答 1

0

删除了对用于将自定义对象编码为 JSON 的 encode_json 挂钩的支持。此功能已被提取到 activesupport-json_encoder gem 中。

将 activesupport-json_encoder gem 添加到 Gemfile 修复此问题。

于 2015-11-03T05:36:31.263 回答