Devise 无法与 Plupload 的 Flash 运行时一起使用
我正在运行 Rails 3.0.9、Devise 1.4 和 Plupload 1.4.3.2。 HTML5 运行时一切正常。
但是,当我将 before_filterauthenticate_user! 添加到我的应用程序控制器并切换到 flash 运行时 时,事情就会变得糟糕。
当我尝试上传一些图像时:
Started POST "/uploads" for 127.0.0.1 at 2011-06-29 12:58:48 +0200
Processing by UploadsController#create as JS
Parameters: {"Filename"=>"me_dark_ui_01.png", "name"=>"me_dark_ui_01.png", "_inzercia_session"=>"BAh7CEkiEF9jc3JmX3Rva2VuBjoGRUZJIjE0NjlmSkZCd25VMkl1UEFzTTFUVTUwTFVYTjRHYkJJSTlGKzBWTXFlSzc0PQY7AEZJIhl3YXJkZW4udXNlci51c2VyLmtleQY7AFRbCEkiCVVzZXIGOwBGWwZpB0kiIiQyYSQxMCQ4SkVLZGVja0dLVk5jbm10MEVoNmRPBjsAVEkiD3Nlc3Npb25faWQGOwBGIiUwY2Y1ZjM4MDRlMGEzOTM3MzQ5ZTQzM2RkNjk5MTc0Mg%253D%253D--b0e6653c44645e7db420dff1dd9908f4b8938e6d", "authenticity_token"=>"469fJFBwnU2IuPAsM1TU50LUXN4GbBII9F+0VMqeK74=", "upload_token"=>"07ea1a1ec4539436878b8e13ae6347164fcd3eac", "_http_accept"=>"application/javascript", "file"=>#<ActionDispatch::Http::UploadedFile:0x520bae0 @original_filename="me_dark_ui_01.png", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"me_dark_ui_01.png\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:C:/Users/Deli/AppData/Local/Temp/RackMultipart20110629-4684-osz0l9>>, "Upload"=>"Submit Query"}
Completed in 21ms
My Uploads#create action
def create
@upload = Upload.new
@upload.photo = params[:file] if params.has_key?(:file)
# detect Mime-Type (mime-type detection doesn't work in flash)
@upload.photo_content_type = MIME::Types.type_for(params[:name]).to_s if params.has_key?(:name)
@upload.upload_token = params[:upload_token]
@upload.save!
strong textrespond_to :js
end
Plupload 设置:
<% session_key_name = Rails.application.config.session_options[:key] %>
jQuery(document).ready(function() {
$("#uploader").pluploadQueue({
runtimes: 'flash',
url: '<%= uploads_path %>',
max_file_size: '10mb',
multiple_queues: true,
flash_swf_url: "/javascripts/plupload/plupload.flash.swf",
silverlight_xap_url: "/javascripts/plupload/plupload.silverlight.xap",
multipart: true,
multipart_params: {
'_http_accept': 'application/javascript',
'authenticity_token' : '<%= form_authenticity_token %>',
'upload_token' : '<%= @upload_token %>',
'<%= session_key_name %>' : encodeURIComponent('<%= u cookies[session_key_name] %>')
},
filters: [
{title: "Images", extensions: "jpg,jpeg,png"}
],
init: {
FileUploaded: function(up, file, info) {
eval(info["response"]);
}
}
});
});
I'm running Rails 3.0.9, Devise 1.4 and Plupload 1.4.3.2. Everything works fine with HTML5 runtime.
But when I add before_filter authenticate_user! to my application controller and switch to flash runtime things go bad.
When I try to upload some images:
Started POST "/uploads" for 127.0.0.1 at 2011-06-29 12:58:48 +0200
Processing by UploadsController#create as JS
Parameters: {"Filename"=>"me_dark_ui_01.png", "name"=>"me_dark_ui_01.png", "_inzercia_session"=>"BAh7CEkiEF9jc3JmX3Rva2VuBjoGRUZJIjE0NjlmSkZCd25VMkl1UEFzTTFUVTUwTFVYTjRHYkJJSTlGKzBWTXFlSzc0PQY7AEZJIhl3YXJkZW4udXNlci51c2VyLmtleQY7AFRbCEkiCVVzZXIGOwBGWwZpB0kiIiQyYSQxMCQ4SkVLZGVja0dLVk5jbm10MEVoNmRPBjsAVEkiD3Nlc3Npb25faWQGOwBGIiUwY2Y1ZjM4MDRlMGEzOTM3MzQ5ZTQzM2RkNjk5MTc0Mg%253D%253D--b0e6653c44645e7db420dff1dd9908f4b8938e6d", "authenticity_token"=>"469fJFBwnU2IuPAsM1TU50LUXN4GbBII9F+0VMqeK74=", "upload_token"=>"07ea1a1ec4539436878b8e13ae6347164fcd3eac", "_http_accept"=>"application/javascript", "file"=>#<ActionDispatch::Http::UploadedFile:0x520bae0 @original_filename="me_dark_ui_01.png", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"me_dark_ui_01.png\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:C:/Users/Deli/AppData/Local/Temp/RackMultipart20110629-4684-osz0l9>>, "Upload"=>"Submit Query"}
Completed in 21ms
My Uploads#create action
def create
@upload = Upload.new
@upload.photo = params[:file] if params.has_key?(:file)
# detect Mime-Type (mime-type detection doesn't work in flash)
@upload.photo_content_type = MIME::Types.type_for(params[:name]).to_s if params.has_key?(:name)
@upload.upload_token = params[:upload_token]
@upload.save!
strong textrespond_to :js
end
Plupload settings:
<% session_key_name = Rails.application.config.session_options[:key] %>
jQuery(document).ready(function() {
$("#uploader").pluploadQueue({
runtimes: 'flash',
url: '<%= uploads_path %>',
max_file_size: '10mb',
multiple_queues: true,
flash_swf_url: "/javascripts/plupload/plupload.flash.swf",
silverlight_xap_url: "/javascripts/plupload/plupload.silverlight.xap",
multipart: true,
multipart_params: {
'_http_accept': 'application/javascript',
'authenticity_token' : '<%= form_authenticity_token %>',
'upload_token' : '<%= @upload_token %>',
'<%= session_key_name %>' : encodeURIComponent('<%= u cookies[session_key_name] %>')
},
filters: [
{title: "Images", extensions: "jpg,jpeg,png"}
],
init: {
FileUploaded: function(up, file, info) {
eval(info["response"]);
}
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加后问题解决
plupload 配置为 true。
Problem solved with adding
to the plupload configuration.