views:

104

answers:

1

I'm trying to optimize a site I'm building with Django/Flash and am having a problem using Django's iterate over chunks() feature. I'm sending an image from Flash to Django using request.POST data rather than through a form (using request.FILES). The problem I foresee is that if there is large user volume, I could potentially kill memory.

But it seems that Django only allows iterating over chunks with request.FILES. Is there a way to:

1) wrap my request.POST data into a request.FILES (thus spoofing Django)

or

2) use chunks() with request.POST data

A: 

The chunks() method is only available to an django.core.files.uploadedfile.UploadedFile object, which itself is a child of django.core.files.base.File. From the documentation for handling uploaded files:

The final piece of the puzzle is handling the actual file data from request.FILES. Each entry in this dictionary is an UploadedFile object -- a simple wrapper around an uploaded file.

So if you can create your own UploadedFile object, then you could feasibly work some magic with chunks(). I recommend snooping around on DjangoSnippets, which might have some code you can use as an example on how to do this.

jathanism
Much appreciated! I'll look into it.
Sebastian