【发布时间】:2013-09-11 16:51:03
【问题描述】:
在我的 Rails 应用程序 (3.2.12) 中,我使用 jquery-fileupload-rails gem 让用户能够上传个人资料图片。在 Chrome 和 Safari 中一切正常,但在 Internet Explorer 中(我使用版本 10 对其进行了测试)我什至无法选择要上传的文件。当我单击“添加文件”按钮时,他没有显示选择文件的对话框,而是立即触发了对上传操作的空请求,从而导致 json 响应显示一个空的照片对象。这是我当前用于初始化文件上传的 js(我已经从 IE 和 csrf-tokens 的问题中添加了一些代码):
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
dataType: 'json',
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|tiff)$/i
});
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(/\/[^\/]*$/, '/photos?%s')
);
//add csrf token manually for ie iframe transport
$('#fileupload').bind('fileuploadsend', function(event, data) {
auth_token = $('meta[name="csrf-token"]').attr('content');
data.url = data.url + '?authenticity_token=' + encodeURIComponent(auth_token);
$.blueimp.fileupload.prototype.options.send.call(this, event, data);
});
以及我的响应控制器代码,其中我已经(希望是正确的)将内容类型设置为“文本/纯文本”:
format.html {
render json: [@photo.to_jq_upload].to_json,
content_type: 'text/plain', #content_type: 'text/html',
layout: false
}
format.json {
render json: {files: [@photo.to_jq_upload]},
content_type: 'text/plain',
status: :created,
location: @photo
}
有谁知道,如何让它在 IE 中工作,可以帮助我吗?谢谢:)
【问题讨论】:
-
为什么不使用 Paperclip gem,因为它被广泛用于文件上传。这不存在跨浏览器问题。
-
显然问题也出现在 Firefox 中,主要问题似乎是,当单击添加文件按钮时,他没有打开选择文件对话框,而是提交了空表单...
-
感谢您的提示!我实际上已经使用了回形针 gem,但仅用于服务器文件处理和图像处理。有什么我还没有听说过的客户端魔法吗?
标签: ruby-on-rails-3 internet-explorer jquery-fileupload-rails