Reputation: 607
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.
Upvotes: 1
Views: 703
Reputation: 288090
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, including file
ones, in one form. Adding name=
should fix your problem:
'<input type="file" name="myfile" id="myfile" accept="image/jpeg,image/png,image/gif" />'
// ^^^^^^^^^^^^^
Upvotes: 1