简体   繁体   English

Valums文件上传器 - 仅允许单个文件上传

[英]Valums File Uploader - Allow single file upload only

Is there any way to make Valums File Uploader to accept only a single file? 有没有办法让Valums File Uploader只接受一个文件?

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. 现在,使用multiple: false您无法限制要上载的文件数,而是可以让用户逐个上传文件,而不是允许多次选择。

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? 任何人都可以帮助我如何实现这一目标?

To limit uploading to only a single file, I simply used onComplete callback and I removed the upload button, hope this helps: 要限制只上传到一个文件,我只是使用onComplete回调,我删除了上传按钮,希望这有助于:

onComplete: function(id, fileName, responseJSON){
                $('.qq-upload-button').remove();
            }

I think hiding the button is not a very good option, here's what i have done. 我认为隐藏按钮不是一个很好的选择,这就是我所做的。

I basically overwrote the _storeFileForLater method 我基本上覆盖了_storeFileForLater方法

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

                       this._storedFileIds = [];
                       this._storedFileIds.push(id);
                  }
                  else{
                        this._storedFileIds.push(id);
                      }
    }

I force to select one file at time commenting this line 我强制选择一个文件来评论这一行

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

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. 我知道你发布这个已经有一段时间了,但我刚刚了解到Valums File Uploader的2.0版测试版中支持multiple:false参数。

You can download it here . 你可以在这里下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM