rails paperclip image upload Encoding :: UndefinedConversionError(从ASCII-8BIT到UTF-8的“\ xFF”):

时间:2013-06-17 14:02:43

标签: ruby paperclip

我已经使用回形针进行图像存储,当我尝试上传并保存图像时,图像会被保存,但我会在重定向到其他页面时获得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 `

我检查了paperclip gem,它使用binmode打开文件。

1 个答案:

答案 0 :(得分:0)

  

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

将Activesupport-json_encoder gem添加到Gemfile可以解决此问题。