Restrict number of files in multifile

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Restrict number of files in multifile

Manjula

Is there any way to restrict the no of files that can be uploaded using a multifile control?

Right now, I am overriding the OnFileQueued to alert the user if more than 'n' no of files are selected in the file dialog.

But this can only be a temporary solution as I might need to have more than one multifile control in the same page but with different restrictions.

Is there any other way to do this or should this be a new feature request?

Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Dean Brettle
Administrator
If you have more than one MultiFile control, you can override the OnFileQueued method for each one individually by using:

NeatUploadMultiFile.prototype.Controls['multiFileClientID'].OnFileQueued = function (f) {
  // Your code goes here.
};

with a different multiFileClientID for each control.  Right?
Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Manjula

Havent tried that. Will try and let you know.

Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Guest-859
I tried what you said and it didnt work. Inside, the function

NeatUploadMultiFile.prototype.OnFileQueued = function (file)

I am able to read

NeatUploadMultiFile.prototype.Controls['controlid'].FilesToUpload.length

What I need is to somehow differentiate between control1 and control2 which has

different size restrictions.

Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Dean Brettle
Administrator
You just need to override it OnFileQueued with a different function for each of your controls, like this:

NeatUploadMultiFile.prototype.Controls['control1'].OnFileQueued = function(file) {
  if (this.FilesToUpload.length > LIMIT_FOR_CONTROL1)
    ....
};

NeatUploadMultiFile.prototype.Controls['control2'].OnFileQueued = function(file) {
  if (this.FilesToUpload.length > LIMIT_FOR_CONTROL2)
    ....
};

Note that you don't need to modify NeatUpload.js or set NeatUploadMultiFile.prototype.OnFileQueued.

--Dean
Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Guest-859

hello.

i have tried doing

if (this.FilesToUpload.length > LIMIT_FOR_CONTROL1)

but the length still increases. meaning that, if i remove a file, i cant add more file as the length already exceed. how do i make it not increase the length as well ? thanks

Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Dean Brettle
Administrator
Have your OnFileQueued() function call file.Delete() if there are too many files.  That should reduce FilesToUpload.length.

--Dean
Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Guest-859
I know this is an old post but hopefully you can help me. I am at my wits end trying to figure this out. When I try to the above example I am either breaking something or not grasping this somewhere.
My control id is "MultiFile1" and I am adding the following Javascript code below the control.

 <script type="text/javascript">
        window.onload = function(){
            NeatUploadMultiFile.prototype.Controls['MultiFile1'].OnFileQueued = function(file) {
                if (this.FilesToUpload.length > 2) {
                    file.Delete();
                    alert("test");
                }
        }
           
        };
        </script>

As you can see I set 2 at the max with the intent that a person cannot choose more than 2 files. The results are that if I select 1 or 2 files select one or two files they do not show up. If I select more than 2 then the alert works but of course still no files show up in the que. I cannot figure out what I might be doing wrong.
Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Dean Brettle
Administrator
I think you need to have your OnFileQueued call NeatUploadMultiFile.prototype.OnFileQueued(file) to add the file to the queue. --Dean
Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Guest-859
Not sure if I am following. Where would I insert NeatUploadMultiFile.prototype.OnFileQueued(file) within the snippet? (Sorry but my javascript knowledge is full of gaps and anyone with sense should ban me from in ASP.net).
Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Dean Brettle
Administrator
Add the call in an "else" clause associated with your existing "if" statement. --Dean
Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Guest-859
I think I am partially there. I used the following code, however the que no longer displays any files. At first I thought it was not working but then I realized that at 2 files out of 10 I had selected  actually uploaded. Is there a way to display files that will upload in the que?

<script type="text/javascript">
    window.onload = function() {
        NeatUploadMultiFile.prototype.Controls['MultiFile1'].OnFileQueued = function(file) {

            if (this.FilesToUpload.length > 2) {
                file.Delete();
            }
            else
           {
                NeatUploadMultiFile.prototype.OnFileQueued(file);
            }
        }
    };

</script>
Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Dean Brettle
Administrator
Sorry, my bad. I think you need the else clause to say:

NeatUploadMultiFile.prototype.OnFileQueued.call(this, file);

--Dean
Reply | Threaded
Open this post in threaded view
|

Re: Restrict number of files in multifile

Guest-859
That was it. Thanks! For anyone else that might need this, here is the final javascript code I used and it works great:

<script type="text/javascript">
    window.onload = function() {


        NeatUploadMultiFile.prototype.Controls['MultiFile1'].OnFileQueued = function(file) {


            if (this.FilesToUpload.length > 2) {
                file.Delete();
            }
            else {

                NeatUploadMultiFile.prototype.OnFileQueued.call(this, file);
               
            }
        }
    };

</script>

Just make sure you replace "MultiFile1" with the control id and change 2 to be the maximum number of files allowed.