jQuery文件上传不再调整图像大小

Ben*_*itD 3 file-upload jquery-plugins image-resizing

我上传和调整图像文件大小三个月后,我在项目中使用jQuery文件上传.一切都工作正常,直到上周.该插件不再调整图像大小(最新的谷歌浏览器和最新的Firefox).

我在此页面上使用相同的基本配置https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin

有人有同样的问题,也许有解决方案吗?

谢谢

Dev*_*man 15

我无法让客户端图像调整大小工作,我发现这是因为我已经覆盖了add方法,并且没有包含代码来执行原始方法中的图像大小调整.我会发布我的解决方案,希望它能帮助拯救某些人一些挫败感.

<form action="/path/to/uploadHandler" id="multiple-image-upload" enctype="multipart/form-data" method="post" accept-charset="utf-8">
    <input name="files" multiple="multiple" id="files" type="file">
</form>

<div id="file-upload-progress">
    <div id="upload-progress">
        <div class="bar" style="width: 0%;"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    $('#multiple-image-upload').fileupload({
        dataType: 'json',
        // Enable image resizing, except for Android and Opera,
        // which actually support image resizing, but fail to
        // send Blob objects via XHR requests:
        disableImageResize: /Android(?!.*Chrome)|Opera/
            .test(window.navigator.userAgent),
        process:[
            {
                action: 'load',
                fileTypes: /^image\/(gif|jpeg|png)$/,
                maxFileSize: 20000000 // 20MB
            },
            {
                action: 'resize',
                maxWidth: 1920,
                maxHeight: 1200,
                minWidth: 800,
                minHeight: 600
            },
            {
                action: 'save'
            }
        ],
        add: function (e, data) {
            data.context = $('<p/>').text('Uploading '+data.files[0].name+'...').appendTo("#file-upload-progress");
            var $this = $(this);
            data.process(function () {
                return $this.fileupload('process', data);
            }).done(function() {
                data.submit();
            });
        },
        done: function (e, data) {
            data.context.html('<img src="'+data.result.files[0].thumbnailUrl+'" alt="'+data.result.files[0].name+'" />');
        },
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#upload-progress .bar').css(
                'width',
                progress + '%'
            ).text(
                progress + '%'
            );
        }
    });
})();
Run Code Online (Sandbox Code Playgroud)

  • tks,我有同样的问题,我在自定义添加中调用.submit,但没有调用进程.fwiw,我不需要添加自定义进程:参数,一旦我将我的代码从data.submit()更改为.process(function(){return fileUploader.fileupload('process',data);}).done (function(){data.submit()}它工作正常,并观察了官方howto(https://github.com/blueimp/jQuery-File-Upload/wiki/Client-side)中概述的imageMaxHeight:xyz等参数 - 图像调整大小). (4认同)