I have a script that creates a popup with form according to webpy cookbook:
jQuery('#logo').click(function(){
var content = ('<h1>Upload logo</h1>' +
'<form method="POST" enctype="multipart/form-data" action="/upload">' +
'<input type="file" id="myfile" accept="image/jpeg,image/png,image/gif" />' +
'<button id="upload" type="submit">Загрузить</button></form>'
);
popup(content);
});
in my python app I have a simple code for relevant class:
class uploadPage(allpages):
def POST(self):
x = web.input(myfile={})
print x
but when I try to upload file I always get empty Storage object.
The
<input type="file" />element has no name attribute which would indicate the name of the file in the form submission. The name is required since you can have multiple input fields, includingfileones, in one form. Addingname=should fix your problem: