2

Is there any way to make Valums File Uploader to accept only a single file?

Right now, with multiple: false you cannot limit the number of files to upload but instead you can get the user to upload files one-by-one rather than allowing multiple selection.

I need the user to upload a single file only. If another file is being selected after uploading a file, the uploaded file should be replaced by the current one.

Can anyone help me in how to achieve this?

Subliminal Hash
  • 13,614
  • 20
  • 73
  • 104

4 Answers4

3

To limit uploading to only a single file, I simply used onComplete callback and I removed the upload button, hope this helps:

onComplete: function(id, fileName, responseJSON){
                $('.qq-upload-button').remove();
            }
rationalboss
  • 5,330
  • 3
  • 30
  • 50
Titenis
  • 555
  • 7
  • 14
  • That is the solution I finally came up with. But I guess this is not a good solution. What about if user wants to re-upload another file instead of the one that is just uploaded? (change the uploaded picture, say because he/she didn't like it and/or uploaded the wrong picture?) – Subliminal Hash Sep 06 '12 at 07:13
  • I would probably add delete button by the uploaded files' filename. The button would delete that file from server(ajax) and reload file uploader. But thats all external code, separated from uploader. – Titenis Sep 06 '12 at 14:02
1

I think hiding the button is not a very good option, here's what i have done.

I basically overwrote the _storeFileForLater method

 qq.FileUploaderBasic.prototype._storeFileForLater = function(id){
                  if(!this._options.multiple){ 

                       this._storedFileIds = [];
                       this._storedFileIds.push(id);
                  }
                  else{
                        this._storedFileIds.push(id);
                      }
    }
vijay tyagi
  • 2,226
  • 3
  • 20
  • 31
0

I force to select one file at time commenting this line

if (this._options.multiple){input.setAttribute("multiple", "multiple");} and multiple: qq.UploadHandlerXhr.isSupported(),

0

I know it's been a while since you posted this, but I just learned that the multiple: false parameter is supported in version 2.0 beta of Valums File Uploader.

You can download it here.

Dan Torrey
  • 1,379
  • 15
  • 25