18

I'm using plupload.

How do you reset the uploader after the transfer queue completes, so the user can upload more files if they want?

henrywright
  • 10,070
  • 23
  • 89
  • 150
Oksana
  • 13,442
  • 10
  • 53
  • 89

6 Answers6

31

uploader.splice(); will remove all files from the queue and make uploader object ready to start over.

jayarjo
  • 16,124
  • 24
  • 94
  • 138
  • 2
    wow-- really.. who would have thought? `splice();` I racked my brains for ages on this.. Nice one! – Piotr Kula May 03 '12 at 14:19
  • 7
    Just so people know a new option was added to the queue widget to reset the upload form to allow multiple uploads. As documented on http://www.plupload.com/docs/pluploadQueue simply add the option `multiple_queues: true,` to your options. – Jeff Wilbert Mar 30 '14 at 03:20
  • 1
    @JeffWilbert Either I'm missing something or the [docs](http://www.plupload.com/docs/pluploadQueue) says incorrectly, that `multiple_queues` is set to `true` by default. This is **not** true. It is `false` by default and must be forced `true` by developer. – trejder Jun 04 '14 at 15:07
  • 1
    @trejder That could be the case. It does appear that the docs say its true by default. But according to http://www.plupload.com/punbb/viewtopic.php?id=370 in v1.3 when it was first added to the script it was disabled by default. So who knows when they defaulted it to true if it really is defaulted to true now and the docs are wrong, would have to DL the latest version and test. – Jeff Wilbert Jun 05 '14 at 11:49
8
uploader.splice();

uploader.refresh();

In that sequence... Works on jquery.ui mode.

Amul
  • 139
  • 2
  • 3
  • Either I'm missing something, or this solution unfortunately doesn't work for QueueWidget (buttons disappears after `.splice()`). So it seems, that your answer is fine only for UI mode, as you wrote (+1). – trejder Jun 06 '14 at 10:50
6

There is now an option to automatically reset the queue widget once uploads are complete.

http://www.plupload.com/documentation.php

multiple_queues

Boolean state if you should be able to upload multiple times or not.

Brett Postin
  • 11,215
  • 10
  • 60
  • 95
2

jayarjo's solution removes the files from the uploader, but doesn't restore the Add/upload buttons.

This one works...

http://www.plupload.com/punbb/viewtopic.php?pid=1360#p1360

Asif Sheikh
  • 1,065
  • 2
  • 8
  • 18
1

In this sequence:

        var uploader = $('#uploader').plupload('getUploader');
        uploader.splice();
        uploader.refresh();

I'm using a function that was resetting the form with some other content but was unable to reset plupload. I don;t mind that it does not come again the Drag Files here text, although I think that it can be monkeyed.. It might have something to do with the count. For instance, I have these params:

                   uploader_0_name          account-disabled-1.png
                   uploader_0_status    done
                   uploader_count           1

Perhaps removing these inputs is not a good idea, but restoring them to their initial state could work.. I will look into that and come back as it develops.. Thanks for the nice advices.

Jean G.T
  • 1
  • 10
  • 25
1

I bind to the UploadComplete event to remove and re-initialize the plupload object when the upload completes. It turned out to be the best implementation for me.

With this implementation, just call init_uploader() to initialize- in this case, on jquery page load complete.

HTML:

<div id="uploader_wrapper"></div>

Javascript:

function init_uploader()
{
    $("#uploader_wrapper").append('<div id="uploader"><img src="/images/loading.gif" /></div>');

    $("#uploader").pluploadQueue({
        runtimes: 'html5,html4,gears,browserplus,flash,silverlight',
        url: 'some_url',
        max_file_size: '10mb',
        chunk_size: '1mb',
        unique_names: true,
        filters: [
            { title: "Image files", extensions: "jpg,gif,png,jpeg" }
        ],
        flash_swf_url: 'http://www.plupload.com/plupload/js/plupload.flash.swf',
        silverlight_xap_url: 'http://www.plupload.com/plupload/js/plupload.silverlight.xap'
    });

    var uploader = $('#uploader').pluploadQueue();

    uploader.bind("UploadComplete", function () {
        $("#uploader").remove();
        init_uploader();
    });
}

$(function () {
    init_uploader();
});