2015-01-20 4 views
6

रेल 4.2 के उन्नयन के बाद मेरा कोड डेटाबेस पर अपलोड की गई फ़ाइल को सहेजने के लिए (पृष्ठ) त्रुटि संदेश में विफल रहता है: 'स्ट्रिंग में शून्य बाइट' होता है।रेल 4.2: file_field, स्ट्रिंग में शून्य बाइट त्रुटि

मैंने केवल एक मॉडल और बाइनरी फ़ील्ड के साथ एक नया रेल 4.2 ऐप बनाया है।

:001 > entry = Entry.new 
=> #<Entry id: nil, name: nil, file: nil, created_at: nil, updated_at: nil> 
:002 > f = File.open('public/icon-sidesearch.png', 'rb') { |io| io.read } 
=> "\x89PNG\r\n\u001A\n\u0000\... more binary data" 
:003 > entry.file = f 
ArgumentError: string contains null byte 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/oid/bytea.rb:8:in `unescape_bytea' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/oid/bytea.rb:8:in `type_cast_from_database' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/type/binary.rb:26:in `changed_in_place?' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute.rb:54:in `changed_in_place_from?' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:74:in `attribute_changed_in_place?' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:149:in `block in changed_in_place' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:148:in `select' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:148:in `changed_in_place' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:141:in `attributes_changed_in_place' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:62:in `changed_attributes' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activemodel-4.2.0/lib/active_model/dirty.rb:173:in `attribute_changed?' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:107:in `save_changed_attribute' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:94:in `write_attribute' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activerecord-4.2.0/lib/active_record/attribute_methods.rb:50:in `__temp__6696c656' 
    from (irb):5 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start' 
... 9 levels... 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/spring-1.2.0/lib/spring/commands/rails.rb:6:in `call' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/spring-1.2.0/lib/spring/command_wrapper.rb:38:in `call' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/spring-1.2.0/lib/spring/application.rb:183:in `block in serve' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/spring-1.2.0/lib/spring/application.rb:156:in `fork' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/spring-1.2.0/lib/spring/application.rb:156:in `serve' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/spring-1.2.0/lib/spring/application.rb:131:in `block in run' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/spring-1.2.0/lib/spring/application.rb:125:in `loop' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/spring-1.2.0/lib/spring/application.rb:125:in `run' 
    from /Users/jose/.rvm/gems/[email protected]_sice/gems/spring-1.2.0/lib/spring/application/boot.rb:18:in `<top (required)>' 
    from /Users/jose/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /Users/jose/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from -e:1:in `<main>' 
कोई भी विचार

क्या हो रहा हो सकता है:

create_table "entries", force: :cascade do |t| 
    t.string "name" 
    t.binary "file" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
end 

कंसोल का उपयोग करके?

+2

इस प्रयास करें तय है: 'entry.file = Base64.encode64 (च)' – Rodrigo

+0

धन्यवाद रॉड्रिगो। यह वही है जो मैं अब काम करने के लिए कर रहा हूं। अन्य परियोजनाओं को देखते हुए लगता है कि मैं _text_ फ़ील्ड का उपयोग करता हूं और आपके द्वारा सुझाए गए फ़ाइलों की सामग्री को एन्कोड/डीकोड करता हूं। – JAG

उत्तर

2

जैसा कि बताया जा here, कि एक रेल बग और पर 4.2.1

https://github.com/rails/rails/pull/17680

+0

इस उत्तर के लिए धन्यवाद! निश्चित रूप से मुझे क्या चाहिए। रूबी 2.3.1 के साथ –

+1

रेल 4.2.6 और पीजी मणि 0.18.4 और अभी भी विफल रहता है। – Juanin

+0

इसे देखते हुए कुछ सामान्य रूप से सामान्य स्ट्रिंग @ जुआनिन ने इसे हल किया? – MBHNYC

संबंधित मुद्दे