【问题标题】:Input [type=file] returns empty value输入 [type=file] 返回空值
【发布时间】:2012-01-15 10:03:15
【问题描述】:

我有一个脚本可以根据 webpy 食谱创建一个带有表单的弹出窗口:

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);
});

在我的 python 应用程序中,我有一个相关类的简单代码:

class uploadPage(allpages):
    def POST(self):
        x = web.input(myfile={})
        print x

但是当我尝试上传文件时,我总是得到空的存储对象。

【问题讨论】:

    标签: python upload web.py


    【解决方案1】:

    &lt;input type="file" /&gt; 元素没有 name 属性,该属性将在表单提交中指示文件的名称。该名称是必需的,因为您可以在一个表单中拥有多个输入字段,包括 file 字段。添加name= 应该可以解决您的问题:

    '<input type="file" name="myfile" id="myfile" accept="image/jpeg,image/png,image/gif" />'
    //                  ^^^^^^^^^^^^^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 2015-04-18
      • 2016-01-25
      相关资源
      最近更新 更多