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

Limit queue to 1 item #69

Closed robfrancken closed 5 years ago

robfrancken commented 6 years ago

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.

azulkipli commented 6 years ago

yes I think multiple: false, not working

SapientHetero commented 5 years ago

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;
robfrancken commented 5 years ago

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 = [];
SapientHetero commented 5 years ago

Glad to hear it helped. Thanks for letting me know.

On Mon, Oct 29, 2018, 7:44 PM Rob Francken notifications@github.com wrote:

Hi @SapientHetero https://github.com/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 = [];

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/danielm/uploader/issues/69#issuecomment-434121050, or mute the thread https://github.com/notifications/unsubscribe-auth/AlmII-V5j9fd_rR8ny1D56n-MS6yFy74ks5up5LlgaJpZM4Srel7 .