Plupload - Restrict to only one file

后端 未结 13 1287
攒了一身酷
攒了一身酷 2021-02-02 10:15

I don\'t see an option in the plupload API docs on restricting the number of files uploaded, to any number, even 1.

Doc fail? or Feature fail? If it doesn\'t exist I\'ll

13条回答
  •  南旧
    南旧 (楼主)
    2021-02-02 11:11

    Try this. It works fine for me.

    uploader.bind('FilesAdded', function(up, files) {
    
    if(uploader.files.length > 1)
    {
        uploader.removeFile(uploader.files[0]);
        uploader.refresh();// must refresh for flash runtime
    }
    

    . . . resto

    Idea is to test num files in current uploader object. If length is greater than 1, then just use method uploader.removeFile. Notice that argument is files[0] which is not a file id, but complete file object.

    ({id:"p17bqh1v4dp42gdf1gan75p16tp3", name:"gnome-globe.png", size:48456, loaded:0, percent:0, status:1})
    

    Best regards!

提交回复
热议问题