【问题标题】:plupload with webpy用 webpy 上传
【发布时间】:2010-04-16 03:19:09
【问题描述】:

我想通过 HTML5 运行时使用 plupload 上传文件。

这是我的 html/js 代码:

jQuery(function(){
    jQuery("#uploader").pluploadQueue({
        // General settings
        runtimes : 'html5',
        name : 'file',
        url : 'http://server.name/addContent',
        max_file_size :  '${maxSize}$_("GB")',
    });


    jQuery('#form_upload_file').submit(function(e) {
        var uploader = jQuery('#uploader').pluploadQueue();
        // Validate number of uploaded files
        if (uploader.total.uploaded == 0) {
            // Files in queue upload them first
            if (uploader.files.length > 0) {
                // When all files are uploaded submit form
                uploader.bind('UploadProgress', function() {
                if (uploader.total.uploaded == uploader.files.length)
                    jQuery('#form_upload_file').submit();
                });
                uploader.start();
            } else
                alert('You must at least upload one file.');

            e.preventDefault();
        }
    });


});

<form id="form_upload_file" action="#" method="POST">
        <div id="uploader"></div>
        <input type="hidden" name="token" value="token" />
        <input type="hidden" name="idUser" value="$idUser" />
    </form>

所以,当我单击按钮上传时(未调用 submit() 方法),它会向我的服务器发出 OPTIONS HTTP 请求 所以我不知道我必须做什么来保存文件?

这是我的 webpy 代码:

def OPTIONS(self):
        web.header('Content-type', 'text/plain: charset=utf-8')
        web.header('Cache-Control', 'no-store, no-cache, must-revalidate')
        web.header('Cache-Control', 'post-check=0, pre-check=0', False)
        web.header('Pragma', 'no-cache')


    def POST(self):
        input = web.input(_unicode=False, file={})#on récupère les input
        self.copy(input.file.file)
        etc.

知道有什么问题吗?

【问题讨论】:

标签: options web.py


【解决方案1】:

你看过 webpy 的食谱来解决这个问题吗?

http://webpy.org/cookbook/fileupload

这个食谱似乎完成了你想做的事情。

【讨论】:

    猜你喜欢
    • 2013-12-28
    • 2011-03-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 2013-09-12
    • 2023-03-19
    • 2011-03-31
    相关资源
    最近更新 更多