Hi,
I want to upload large image files from actionscript from Flex. The
file upload tutorial 
https://docs.djangoproject.com/en/dev/topics/http/file-uploads/
handles streamed file upload from a form so the file is transformed in
request.FILE['name'], but I don't know how to replicate this in
actionscript. I tried also to transfer the file as POST argument, but
I get error:

in handle_uploaded_file for chunk in f.chunks():
AttributeError: 'unicode' object has no attribute 'chunks'

Is it error in my python code that I have to use only request.FILE or
is it problem in my actionscript? What is the proper way to upload
file without form. Here is my actionscript code:

var upload:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(UploadURL+"?
var="+Math.random());
var sendVars:URLVariables = new URLVariables();
var header:URLRequestHeader = new URLRequestHeader("enctype",
"multipart/form-data");
upload.dataFormat = URLLoaderDataFormat.BINARY;
upload.addEventListener(Event.COMPLETE, image.uploadedEvent);
sendVars.file = image.getBytearray(); // image is a JPEG encoded
ByteArray
request.data = sendVars;
request.method = URLRequestMethod.POST;
request.requestHeaders.push(header);
upload.load(request);

here is django part:

def upload_file(request):
  if request.method == 'POST':
    handle_uploaded_file(request.POST.get('file'))
  return HttpResponse()

def handle_uploaded_file(f):
  destination = open('file.dat', 'wb+')
  for chunk in f.chunks():
      destination.write(chunk)
  destination.close()

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to