Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Flex FileReference objects post files to any URL in such a way that makes it look like a post from a normal form - so you can just use Django's normal file upload functions to handle uploads from Flex. The following is naive in many respects but illustrates the basic plumbing:</p> <p>Flex:</p> <pre><code>private var fileRef:FileReference; private function uploadFile():void { fileRef = new FileReference(); fileRef.browse(); fileRef.addEventListener(Event.SELECT, postFile); fileRef.addEventListener(ProgressEvent.PROGRESS, uploadProgress); fileRef.addEventListener(Event.COMPLETE, uploadComplete); fileRef.addEventListener(IOErrorEvent.IO_ERROR, ioError); } private function postFile(event:Event):void { var req:URLRequest = new URLRequest('http://yourserver/yourapp/upload'); fileRef.upload(req, 'from_flex'); // 'from_flex' is the key you use to refer to the file in django's request.FILES dict } private function uploadProgress(event:ProgressEvent):void { trace('progress'); } private function uploadComplete(event:Event):void { trace('done'); } private function ioError(event:IOErrorEvent):void { trace('error: '+event.toString()); } </code></pre> <p>In Django you just need a view that receives the file and does whatever it is you want:</p> <pre><code>def receive_file(request): received_file = request.FILES['from_flex'] destination = open('recieved_file.jpg', 'wb+') # naively save the file to disk in this case: file_data = received_file.read() destination.write(file_data) destination.close() return HttpResponse() </code></pre> <p>You will also need to add an entry to your urls.py file to expose the above view via some url. See the django docs for more information about dealing with uploaded files:</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload