Topic: Limit Total Queue Size

I need a way to limit the total queue size. I've created a web-app for a robotic disc duplicator, and I want to limit the total queue file size based on the applicable disc (i.e., 650MB CD or 4.7GB DVD). Does anyone know how to accomplish this?

Re: Limit Total Queue Size

This sort of thing gets discussed a lot so searching the forum would be a good idea.

I don't know if you are planning on using one of the widgets or just the core plupload API.  I'm not very familiar with the Widgets, although they use the core API so you can probably do similar manipulations with them.  For the core API you can intercept the Files selected before plupload begins to upload the files by registering a FilesAdded event before you call the init() method - you could then deal with limiting the total upload by size in  some way.

Here is a discussion on the topic of getting the Files selected before plupload does:

http://www.plupload.com/punbb/viewtopic.php?id=473

Also there is a feature request here discussing something similar:

https://github.com/moxiecode/plupload/i … #issue/195

As I mentioned above though, you should search through the forum as this class of problems gets talked about a lot.

3 (edited by glitchn 2011-04-06 01:00:41)

Re: Limit Total Queue Size

Yeah, I saw many posts regarding max_file_size and limiting the number of files. Actually, limiting the number of files to the queue is quite simple using something like 'if(uploader.files.length > 2)'.

I did something similar to hide the submit button on my form that includes plupload until all files in the queue have been uploaded:

uploader.bind('UploadProgress', function() {
   if(uploader.total.uploaded == uploader.files.length) {
      $('#submit').css({'display':'block'});
   }
});

Works like a charm for that. For this, what I'd really like to do is bind to the queue size tally. It seems that would be the easiest way since the queue reports total file size already. However, I haven't been successful in identifying which object to reference.

I'm thinking the code should be something similar, like:

var maxQueueSize = 100;

uploader.bind('FilesAdded', function() {
   if(uploader.total.queued > maxQueueSize) {
      alert('Over disc capacity. Please remove files.'); }
});

Any idea what the correct if statement should be in this case?

Re: Limit Total Queue Size

@glitchn, uploader.files is the queue actually. You can easily find how big it is with: uploader.files.length and you could use uploader.removeFile(file) method to remove extra files from it. uploader.removeFile() takes in a file object, not index. For the first element in the queue for example it will be: uploader.removeFile(uploader.files[0]);

If you want to see your issue fixed, do not report it here, do it on - GitHub.

5 (edited by glitchn 2011-04-06 17:53:18)

Re: Limit Total Queue Size

Davit, when I test uploader.files.length, I get the total number of files in the queue. However, I need the total file size adding up all files queued. That way when a user queues more than 650MB when burning a CD, I can alert the user that files must be removed from the queue since this duplicator doesn't disc span.

What am I doing wrong? Thanks, ~Brian

Re: Limit Total Queue Size

@glitchn, oh then you do not need uploader.total.queued, which is actually just a number of files in queue. Try uploader.total.size.

If you want to see your issue fixed, do not report it here, do it on - GitHub.

7 (edited by glitchn 2011-04-06 20:33:32)

Re: Limit Total Queue Size

Thanks davit. I finally got it setup. The problem was that I was calling the wrong event. I was using FilesAdded and it would come back as zero. This is because it was reporting the total.size prior to actually changing the queue. Now it works using:

/* Check the queue after files added to see if the total size of all files combined exceeds allowed limit. */

var maxQueueSize = 681574400; // Size in bytes. This is set to 650MB.
uploader.bind('QueueChanged', function(up) {
   if(uploader.total.size > maxQueueSize) {
      alert("Total size of all files exceeds disc capacity! Remove some files!");
   }
});

I'll probably add some more code to prevent upload until the queue is reduced to less than the limit, but for now, it works! Thanks again for the assist!

~Brian

Re: Limit Total Queue Size

All, in case anyone needs this... I've got it setup for my disc duplicator, but the premise is the same for most use cases in which you need to limit the combined size of all files in the queue prior to upload.

/* Hide the form submit button until all files have been uploaded to the server. */
uploader.bind('UploadProgress', function() {
   if(uploader.total.uploaded == uploader.files.length) {
      $('#submit').css({'display':'block'});
   }
});

/* Check to see if the upload queue exceeds disc capacity based on disc type. */
var maxCDSize = 681574400;
var maxDVDSize = 5046586572;
uploader.bind('QueueChanged', function(up) {
   if(uploader.total.size > maxCDSize && disc == 'CD') {
      $(".plupload_start").addClass("plupload_disabled");
      alert("Total size of all files exceeds disc capacity!\nPlease remove some files or change disc type to DVD.");
   }
   if(uploader.total.size > maxCDSize && disc == 'DVD') {
      $(".plupload_start").addClass("plupload_disabled");
      alert("Total size of all files exceeds disc capacity!\nPlease remove some files.");
   }
});

Note that I'm calling a global JS variable named 'disc'. This is set on my form with a drop down menu that redeclares the global variable 'disc' whenever it is changed. I'm also disabling the Start Upload button so the user has to select some files to remove before being able to upload. I wanted to give the user the option to choose which files to remove, so that's why I'm not programmatically removing files from the queue.

Anyhow, hopes this helps someone and thanks again davit!

~Brian

Re: Limit Total Queue Size

Thanks for sharing, Brian smile

If you want to see your issue fixed, do not report it here, do it on - GitHub.