【问题标题】:Uploadify IO error (django-filebrowser)Uploadify IO 错误(django-filebrowser)
【发布时间】:2011-09-02 22:13:48
【问题描述】:

我在尝试使用 django-filebrowser(使用 uploadify)上传文件时收到“IO 错误”。

我应该澄清一下,这不起作用的唯一情况是在 OSX 上使用 Firefox 4 时。 Windows 上的 IE8 可以正常工作。

此外,当使用本地开发服务器时,它也适用于 Firefox。

我还应该注意,我在 uplodify 自己的网站演示中遇到了这个确切的错误。

这是我从wireshark看到的:

POST /djadmin/filebrowser/check_file/ HTTP/1.1
Host: xxx
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept: application/json, text/javascript, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: xxx
Content-Length: 57
Cookie: csrftoken=xxx sessionid=xxx
Authorization: Basic xxx
Pragma: no-cache
Cache-Control: no-cache

UPBWID=fd.png&folder=%2Fdjadmin%2Ffilebrowser%2Fupload%2FHTTP/1.1 200 OK
Date: Thu, 26 May 2011 20:08:30 GMT
Server: Apache/2.2.9
Vary: Accept-Language,Cookie
Content-Language: el
Content-Length: 2
Connection: close
Content-Type: text/html; charset=utf-8

{}

据我所知,{} 的返回值是可以的。

这是我从 apache 获得的唯一输出: xxx - 用户 [26/May/2011:20:08:30 +0000] "POST /djadmin/filebrowser/check_file/HTTP/1.1" 200 2 "xxx/djadmin/filebrowser/upload/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"

我可以看到很多人都遇到了同样的问题。 通常归咎于 mod_security、mod_wsgi 以及与浏览器/flash 插件的模糊不兼容。

没有运行 mod_security。 我正在使用 mod_wsgi 运行 django(并且以老式方式上传文件没有任何问题)。

请帮忙!

【问题讨论】:

    标签: django apache uploadify


    【解决方案1】:

    您可能会遇到一个问题,即您没有发布 post 方法所需的 csrf 令牌。您可以使用 @csrf_exempt 装饰器,或添加要上传的数据。将 {% csrf_token %} 添加到您的表单并将表单序列化到 postData 设置。对于第三版,我使用的是这样的:

    (function ($) {
        $.fn.serializeJSON = function () {
            var json = {};
            jQuery.map($(this).serializeArray(), function (n, i) {
                json[n['name']] = n['value'];
            });
            return json;
        };
    })(jQuery);
    
    
    $('#id_filefield').uploadify({
        'swf'  : '{{ STATIC_URL }}js/libs/uploadify/uploadify.swf',
        'uploader'    : '{% url 'upload_form' %}',
        'cancelImage' : '{{ STATIC_URL }}js/libs/uploadify/uploadify-cancel.png',
        'checkExisting' : false,
        'auto'      : true,
        'postData': $('#file_upload_form').serializeJSON(),
        'multi': true,
        'uploaderType': 'flash',
        'requeueErrors': false,
        'fileObjName': 'filefield',
        'fileSizeLimit': 1024000,
        'onSelect': function() { $('#id_filefield').uploadifySettings('postData',   $('#file_upload_form').serializeJSON()); },
        'onQueueComplete': function() { ajaxdialog.dialog('close'); },
      });
    

    显然你不想只是剪切和粘贴这个,但它应该让你知道我在说什么。

    【讨论】:

    • 我帖子中显示的 check_file 函数已经使用了 csrf_exempt 装饰器。
    猜你喜欢
    • 1970-01-01
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-13
    • 1970-01-01
    相关资源
    最近更新 更多