Uploadify IO error (django-filebrowser)
I am getting a 'IO ERROR' while trying to upload a file using django-filebrowser (that uses uploadify).
I should clarify that the only case when this doesn't work is when using Firefox 4 on OSX. IE8 on windows works.
Also, it works with Firefox too when using the local dev server.
I should also note that i am getting this exact error on uplodify's own website demo.
This is what i can see from 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开发者_JAVA技巧 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
{}
As far as i know, a return value of {} is ok.
This is the only output i get from apache: xxx - user [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"
I can see that a lot of people are experiencing the same issue. Usual blame goes to mod_security, mod_wsgi and vague incompatibilities with browsers/flash plugin.
I am not running mod_security. I am running django using mod_wsgi (and don't have any trouble uploading files the old fashioned way).
Please help!
You may be having an issue where you're not posting the csrf token that's required on post methods. You can use the @csrf_exempt decorator, or add the data to uploadify. add a {% csrf_token %} to your form and serialize the form to the postData setting. For version three I'm using something like this:
(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'); },
});
obviously you don't want to just cut and paste this, but it should give you an idea of what i'm talking about.
精彩评论