save!
在新创建的ActiveRecord对象上:
ActiveRecord::RecordInvalid (Validation failed: Content type is not included in the list):
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/validations.rb:946:in `save_without_transactions!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:112:in `save!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:80:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:100:in `transaction'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:112:in `save!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:120:in `rollback_active_record_state!'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:112:in `save!'
/app/controllers/photos_controller.rb:13:in `create'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
因此,似乎没有正确发送内容类型。事实上,Flash发送的是一种
application/octet-stream
,在我期望的地方
image/png
var request:URLRequest = new URLRequest(paramObj.serverUrl + "/albums/" + paramObj.albumId + "/photos");
var variables:URLVariables = new URLVariables();
variables["photo[title]"] = file.name;
variables["authenticity_token"] = paramObj.authenticity_token;
variables["commit"] = "Upload Photo";
request.data = variables;
request.method = URLRequestMethod.POST;
file.upload(request, 'photo[uploaded_data]');
表单参数都存在于Flash上载中,您可以从常规浏览器上载中获得这些参数。在运行数据包嗅探器之后,我能看到的唯一真正区别是内容类型不同。
模型使用附件_-fu,如下所示:
class Photo < ActiveRecord::Base
belongs_to :album
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 10.megabytes,
:thumbnails => {
:thumb => '100x100>',
:large => '800x600>',
}
validates_as_attachment
end
那么,如何修复flash发送的内容类型?而且,为什么附件_-fu信任浏览器发送的内容类型,而不是使用
magic numbers
我注意到如果我移除
:content_type => :image
或者
validates_as_attachment
,或者如果我将控制器更改为调用
save(false)