jquery.uploadify图片上传插件,当图片超出设置sizeLimit时,如何进行错误处理?

使用jquery.uploadify.v2.1.0开发时,将图片大小限制为不超过4M,想在用户图片超过这个大小的时候弹出对话框报错。但是onSelect事件不触发,onSelectOnce事件触发但是无法拿到图片大小,onSelectError/onError/onUploadError均不触发。想问下有谁处理过类似的情况么?

return this.each(function () {
            var $this = $(this);
            $this.uploadify({
                uploader: uploaderUrl,
                cancelImg: '',
                buttonImg: "http://img.soufun.com/secondhouse/image/erp/icon_add2img.jpg",
                expressInstall: 'http://img.soufun.com/secondhouse/image/erp/expressInstall.swf',
                width: 108,
                height: 30,
                fileDesc: '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
                fileExt: '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
                sizeLimit: 4194304,      
                auto: false,            
                multi: true,           
                onSelect: function (e, queueId, fileObj) {
                    alert(1)            //图片超出大小时不触发
                    $this.uploadifySettings('script', postUrl);
                },
                onSelectOnce: function (e, data) {
                                        //一直触发但拿不到用户上传的图片大小的值
                    totalImgCount += data.fileCount;
                    if (totalImgCount > options.maxCount) {
                        alert("最多上传" + options.maxCount + "张");
                        return;
                    }

                    $this.parent().append(processDom);

                    $this.uploadifyUpload();
                },
                uploadifyOverSize : function(){
                    //图片大小超出时不触发
                    alert(123);
                },
                onSelectError: function () {
                //图片大小超出时不触发
                    alert(456);
                },
                onUploadError : function(){
                //图片大小超出时不触发
                    alert(789)
                },
                onError : function(){
                ////图片大小超出时不触发
                    alert(1011)
                },
                onProgress: function (event, queueId, fileObj, data) { //data对象有四个属性percentage、 bytesLoaded、allBytesLoaded、speed
                    var process_width = data.percentage / 100 * 200 + "px";
                    $this.parent().find("img.imgprocess").css({
                        width : process_width
                    });
                    if (data.percentage == 100) {
                        $this.parent().find("div.processContainer").remove();
                    }
                },
                onComplete: function (event, queueId, fileObj, response, data) {
                    if (options.domType == "normal") {
                        $this.parent().append(dom_normal);
                    }
                    options.onComplete(fileObj, response);
                },
                queueID: 'divQueue',
                scriptAccess: 'always'
            })
阅读 3.9k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进