Tornado handler thinks POST is missing argument when Firebug shows the argument being sent
Question
I have a simple form using a POST method, consisting of a text box and a file. After hitting submit, I can see the post in Firebug as follows:
Parts multipart/form-data
posttext Some text
image BlahJFIFBlahExifBlahPhotoshopBlahBinaryStuff etc...
The Tornado handler that receives it looks like:
class NewPostHandler(BaseHandler, MessageMixin):
@tornado.web.authenticated
def post(self):
message = {
'posttext':self.get_argument('posttext'),
'image':self.get_argument('image'),
etc
But Tornado's handler returns:
[W 100618 23:07:32 web:775] 404 POST /a/message/new (127.0.0.1): Missing argument image
I'm not quite sure what I'm doing wrong here. Am I correct in thinking 'argument' means a input element's 'name' attribute? How can I make the handler see the argument?
Thanks for your help, I've been struggling with this for an hour and must admit I'm stumped!
Solution
For file uploads you should use self.request.files
instead of self.get_argument()
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow