I'm trying to use a script for multiple file uploads, like swfupload or uploadify on my django application but no matter what I try, I always get a 403 forbidden error for the upload URL. If I try to run the 'same' code (just different links to same files) independently, it works like a charm.
Any idea if I'm missing something on my main code or is there some kind of setting that I don't know about?
This is totally related with
CSRF protection
. In my case I solved that issue such that,views.py
Because flash useses its own session while uploading, you should set
csrf_token
value in your middleware such thatswfupload.py
For the last step, you should set
csrftoken
as post parameter in your javascript forSWFUpload
settings such thatphoto_upload.html
Just add an extra data when initializing Uploadify (make your changes on "swf" and "uploader" settings):
I use uploadify in my django project, get 403 error too, because django has CSRF protection. so i change this function in my views.py solve this problem.
Thank you very much, brsbilgic. I've tried your solution, and it worked! By the way, the middleware snippet should be modified to:
This is probably related to the flash cookie bug: your client has an authentication cookie that the flash is not including in its request to the server. Since the request doesn't have the auth cookie, it gets rejected with a 403.