我正在使用
ruby 2.2.0
paperclip (4.3.2)
aws-sdk (1.66.0)
尝试将文件上传到AWS S3时出现以下错误
NoMethodError - undefined method `size' for nil:NilClass:
paperclip (4.3.2) lib/paperclip/attachment.rb:466:in `reset_file_if_original_reprocessed'
paperclip (4.3.2) lib/paperclip/attachment.rb:110:in `assign'
paperclip (4.3.2) lib/paperclip/has_attached_file.rb:66:in `block in define_setter'
activerecord (4.2.0) lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
activerecord (4.2.0) lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
actionpack (4.2.0) lib/action_controller/metal/strong_parameters.rb:183:in `each_pair'
activerecord (4.2.0) lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
activerecord (4.2.0) lib/active_record/persistence.rb:249:in `block in update'
activerecord (4.2.0) lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
activerecord (4.2.0) lib/active_record/transactions.rb:220:in `transaction'
activerecord (4.2.0) lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
activerecord (4.2.0) lib/active_record/persistence.rb:248:in `update'
这个错误对我来说似乎很奇怪,因为上传到S3工作并且文件存储在那里:
[paperclip] saving /users/2/identity_documents/xxx.PDF
[AWS S3 200 0.768066 0 retries] put_object(:acl=>:private,:bucket_name=>"imp-staging",:content_length=>167130,:content_type=>"application/pdf",:data=>Paperclip::UploadedFileAdapter: xxx.PDF,:key=>"users/2/identity_documents/xxx.PDF")
我也注意到,班级@queued_for_write
中的Attachment
为空。
有人观察到同样的行为吗?
答案 0 :(得分:2)
在筛选完所有相关的Paperclip问题后,我自己解决了这个问题。
我在上传文档后使用after_*_post_process
回调来更新我的模型。在此回调中尝试save
模型时似乎存在问题,因此我切换到update_column
,一切都按预期工作。