Search code examples
pythonfile-uploadtornadoajax-upload

asynchronous file upload with ajaxupload to a tornado web server


I'm using this javascript library (http://valums.com/ajax-upload/) to upload file to a tornado web server, but I don't know how to get the file content. The javascript library is uploading using XHR, so I assume I have to read the raw post data to get the file content. But I don't know how to do it with Tornado. Their documentation doesn't help with this, as usual :(

In php they have something like this:

$input = fopen("php://input", "r");

so what's the equivalence in tornado?


Solution

  • I got the answer.

    I need to use self.request.body to get the raw post data.

    I also need to pass in the correct _xsrf token, otherwise tornado will fire a 403 exception.

    So that's about it.