danielm/uploader

Limit queue to 1 item

robfrancken opened this issue · 4 comments

I'm hoping someone can help me with this.

I have a single upload field, and I'm using the extraData() method to allow naming the file. I'm also using controls to start the upload.

The problem is this. When a user selects a file, and then changes the file before starting the upload, the newly selected file gets added to the queue. How can I override the queue with the last file selected so that I only upload 1 file at a time?

I thought setting multiple: false, would take care of it, but it doesn't appear to do anything, besides limit selection to a single file.

After changing the file, the queue looks like this:

0: a {data: File(103526), widget: l, jqXHR: null, status: 0, id: "zci1bjtmsk"}
1: a {data: File(103526), widget: l, jqXHR: null, status: 0, id: "05ox1qhs1xox"}

I am trying to do this:

onNewFile: function (id, file) {
    var queue = $(this).data('dmUploader').queue;
    var newFile = queue.length; // 1;
    queue = queue[newFile];
},

This gives me an undefined error, so I'm obviously accessing the object incorrectly.

yes I think multiple: false, not working

You could try doing this before adding the replacement file.

var myUploader = $('#drag-and-drop-zone').dmUploader().data();
myUploader.queue = [];
myUploader.queuePos = -1;
myUploader.activeFiles = 0;

Hi @SapientHetero

Thanks for that. Your solution didn't work, but it got me on the right track.

Adding the following in onNewFile() callback did the trick.

var myUploader = $('#drag-and-drop-zone').dmUploader().data();
myUploader.dmUploader.queue = [];