Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code samples for Django + SWFUpload?

Does anyone have any simple code samples for Django + SWFUpload? I have it working perfectly in my PHP application but Django is giving me headaches.

like image 627
Mike Avatar asked Mar 04 '09 22:03

Mike


2 Answers

Unfortunately I can't give you any very detailed code samples, but I have quite a bit of experience with working with SWFUpload + Django (for a photo sharing site I work on). Anyway, here are a few pointers that will hopefully help you on your quest for DjSWF happiness :)

  1. You'll want to use the cookies plugin (if of course you are using some sort of session-based authentication [like django.contrib.auth, and care who uploaded what).

    The cookies plugin sends the data from cookies as POST, so you'll have to find some way of getting this back into request.COOKIES (process_request middleware that looks for a settings.SESSION_COOKIE_NAME in request.POST on specific URLs and dumps it into request.COOKIES works nicely for this :)

  2. Also, remember that you must return something in the response body for SWFUpload to recognize it as a successful upload attempt. I believe this has changed in the latest beta of SWFUpload, but anyway it's advisable just to stick something in there like 'ok'. For failures, make use of something like HttpResponseBadRequest or the like.

  3. Lastly, in case you're having trouble finding them, the uploaded file is in request.FILES :)

If you have anything perplexing I haven't covered, feel free to post something more detailed and I'll be happy to help.

like image 150
obeattie Avatar answered Nov 02 '22 09:11

obeattie


Django version of the samples for SWFUpload:

http://github.com/naltimari/django-swfupload-samples/tree/master

So long uploadify. Great idea but it is just buggy, especially on Windows.

like image 3
Alvin Avatar answered Nov 02 '22 08:11

Alvin