Plupload 和错误生成

发布于 2024-09-19 07:54:58 字数 324 浏览 8 评论 0原文

我正在开发一个使用 plupload 库进行文件上传的应用程序。我似乎无法让文件上传工作,因为存在某种错误,但我无法让此错误发出警报或记录。

有人能够做到这一点吗?

这是我当前的代码:

uploader.bind('Error', function(error){
                    console.log(error);
                });

提前感谢您的帮助!

I am working on an application that uses the plupload library for file uploading. I can't seem to get the file uploading working because there is some kind of error but I can't get this error to alert or log.

Has anyone been able to do this?

Here is my current code:

uploader.bind('Error', function(error){
                    console.log(error);
                });

Thanks in advance for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

紧拥背影 2024-09-26 07:54:58

所以我知道这可能太晚了,但我刚刚开始使用 plupload 并且心情很好......

控制台从不记录任何内容的原因是因为您所做的绑定仅在所有上传完成后才会发生。

您需要将此代码放在 $('form').submit() 行之前:

uploader = $('#plupload').pluploadQueue();
uploader.bind('Error', function(error){
   console.log(error);
});

So I know this is probably way too late, but I just started with plupload and was in a helpful mood...

The reason the console never logs anything is because the binding that you are doing only occurs when all uploads have been completed.

You need to put this code before the $('form').submit() line:

uploader = $('#plupload').pluploadQueue();
uploader.bind('Error', function(error){
   console.log(error);
});
叫嚣ゝ 2024-09-26 07:54:58

绑定到错误事件需要两个参数:

  var uploader = $("#uploader").pluploadQueue();
  uploader.bind('Error', function(uploader, e) {
    console.error(e);
  });

Binding to the error event requires two params:

  var uploader = $("#uploader").pluploadQueue();
  uploader.bind('Error', function(uploader, e) {
    console.error(e);
  });
长发绾君心 2024-09-26 07:54:58

另一个迟到的答案。如果我是你,我会从将以下内容开始:

$('form').submit(function(e) {

更改为:

$('form').bind('submit', function(e) {

以及类似的内容:

$('form').submit();

更改为:

$('form').trigger('submit');

另外,我会将所有这些绑定移出 $(form).submit。

uploader.bind('UploadProgress', function() {
    if (uploader.total.uploaded == uploader.files.length)
       $('form').submit();
});

只是为了简单性和可调试性。

不幸的是仍然不知道你的脚本出了什么问题。也许你错过了:

uploader.init();

也许:

if (uploader.total.uploaded == 0) {

没有触发。

不过,每行后面的一些 console.log 应该会有所帮助。 :)

Another late answer. If I were you i would start with changins stuff like:

$('form').submit(function(e) {

into something like:

$('form').bind('submit', function(e) {

and stuff like that:

$('form').submit();

into:

$('form').trigger('submit');

Also I would move all these binds out of $(form).submit.

uploader.bind('UploadProgress', function() {
    if (uploader.total.uploaded == uploader.files.length)
       $('form').submit();
});

Just for sake of simiplicity and debugability.

Unfortunately still have no idea what's wrong with your script. Maybe you are missing:

uploader.init();

Maybe:

if (uploader.total.uploaded == 0) {

is not triggering.

Nevertheless some console.log after each line should help. :)

夏日浅笑〃 2024-09-26 07:54:58

这是我尝试让它工作的整个代码库

$('#plupload').pluploadQueue({
        runtimes : 'flash, html5',
        url : '/admin/upload/do_upload/',
        filters : [
            {title : "Image Files", extensions : "jpg,gif,png"}
        ],
        flash_swf_url : "/js/admin/plupload/plupload.flash.swf"
    });

    $('form').submit(function(e) {
        alert('EHY');
        var uploader = $('#plupload').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)
                        $('form').submit();
                });

                uploader.start();

                uploader.bind('Error', function(error){
                    console.log(error);
                });
            } else
                alert('You must at least upload one file.');

            e.preventDefault();
        }
    });

Here is my entire code base for trying to get this to work

$('#plupload').pluploadQueue({
        runtimes : 'flash, html5',
        url : '/admin/upload/do_upload/',
        filters : [
            {title : "Image Files", extensions : "jpg,gif,png"}
        ],
        flash_swf_url : "/js/admin/plupload/plupload.flash.swf"
    });

    $('form').submit(function(e) {
        alert('EHY');
        var uploader = $('#plupload').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)
                        $('form').submit();
                });

                uploader.start();

                uploader.bind('Error', function(error){
                    console.log(error);
                });
            } else
                alert('You must at least upload one file.');

            e.preventDefault();
        }
    });
各自安好 2024-09-26 07:54:58

我还在寻找 Plupload 小部件提供的错误处理机制,但没有一个答案有效。所以这是有效的(每个版本 2.1.2):

$(FileUpload.container).pluploadQueue({
        // General settings
        runtimes: 'html5,flash,silverlight,html4',
        url: "saveFiles",
        chunk_size: '1mb',
        rename: true,
        dragdrop: true,
        multipart : true,
        unique_names : true,
        filters: {
            // Maximum file size
            max_file_size: '16mb',
            // Specify what files to browse for
            mime_types: [
                {title: "XML files", extensions: "xml"}
            ]
        },
        // Flash settings
        flash_swf_url: '/plupload/js/Moxie.swf',
        // Silverlight settings
        silverlight_xap_url: '/plupload/js/Moxie.xap',
        init : {
            Error: function(up, args) {
                // Called when error occurs
                Daedalus.localMessage("XML file is not valid!");
            }
        }
    });

“init”对象有更多支持的事件,请参阅 http://www.plupload.com/examples/events

I was also searching for error handling mechanism provided by Plupload widget, none of the answers were working. So here is the working one (per version 2.1.2):

$(FileUpload.container).pluploadQueue({
        // General settings
        runtimes: 'html5,flash,silverlight,html4',
        url: "saveFiles",
        chunk_size: '1mb',
        rename: true,
        dragdrop: true,
        multipart : true,
        unique_names : true,
        filters: {
            // Maximum file size
            max_file_size: '16mb',
            // Specify what files to browse for
            mime_types: [
                {title: "XML files", extensions: "xml"}
            ]
        },
        // Flash settings
        flash_swf_url: '/plupload/js/Moxie.swf',
        // Silverlight settings
        silverlight_xap_url: '/plupload/js/Moxie.xap',
        init : {
            Error: function(up, args) {
                // Called when error occurs
                Daedalus.localMessage("XML file is not valid!");
            }
        }
    });

The "init" object has more supported events, refer to http://www.plupload.com/examples/events

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文