danielm / uploader

A lightweight and very configurable jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.
https://danielmg.org/demo/java-script/uploader
MIT License
1.17k stars 385 forks source link

any method for stop/destroy/clear queue ? #44

Closed leafiy closed 6 years ago

gficher commented 7 years ago

This is supported in devel branch but with some limitations so I decided to modify the code to add a callback method.

Here you go https://gist.github.com/gficher/27a77b5040cf32d7ab92c9ccfcd5d5aa

How to use it? Good question.

The plugin calls onUploadCancel when a upload is aborted.

How do I abort it then? Another good question.

You should use your drag-and-drop element like this:

$('#drag-and-drop-zone').dmUploader('cancel', id);

The ID is a number and not the row ID, so use a integer (from 0 to n)

But how can I get the ID? You are full of good questions!

Just add a button to your file row and bind an event to it

$('#upload-status-panel tbody').on('click', '.btn-cancel', function() {
    // Gets id from row attribute
    var id = $(this).closest('tr').attr('data-id');
    // Aborts upload
    $('#drag-and-drop-zone').dmUploader('cancel', id);
});

Where did data-id come from?

To get thinks easier, add this attr to the file row like this: image

How can I abort the entire queue?

Just run this little puppy

$('#drag-and-drop-zone').dmUploader('cancelAll');
danielm commented 6 years ago

Closing the issue. Newest release includes this.

The difference of what was originally on the devel branch is:

$('#drag-and-drop-zone').dmUploader('cancel', id);

or to do it 'globally', use it without a file ID:

$('#drag-and-drop-zone').dmUploader('cancel');

More info on the Readme.md, or the online demos.

https://danielmg.org/demo/java-script/uploader/controls