Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jquery中通过调整大小将多个图像上载到django后端服务器_Javascript_Jquery_Django_Image Resizing_Image Compression - Fatal编程技术网

Javascript 如何在jquery中通过调整大小将多个图像上载到django后端服务器

Javascript 如何在jquery中通过调整大小将多个图像上载到django后端服务器,javascript,jquery,django,image-resizing,image-compression,Javascript,Jquery,Django,Image Resizing,Image Compression,我使用Jquery文件上传和压缩的图像代码与此我可以选择多个图像,但它只压缩和上传最后选择的图像 那么,如何通过压缩上传多个图像呢?plzz建议需要进行哪些修改 Html代码: <input id="fileupload" type="file" name="file" multiple> 然后将其保存到数据库中。 一切都很好。即使图像在输出时也会被压缩,但我们希望一按按钮就可以压缩多个图像并保存回数据库。 欢迎任何建议。。。 谢谢你 function csrfSafeMetho

我使用Jquery文件上传和压缩的图像代码与此我可以选择多个图像,但它只压缩和上传最后选择的图像

那么,如何通过压缩上传多个图像呢?plzz建议需要进行哪些修改

Html代码:

<input  id="fileupload" type="file" name="file" multiple>
然后将其保存到数据库中。 一切都很好。即使图像在输出时也会被压缩,但我们希望一按按钮就可以压缩多个图像并保存回数据库。 欢迎任何建议。。。 谢谢你

function csrfSafeMethod(method) {
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$(function () {
'use strict';
var csrftoken = $.cookie('csrftoken');
var url = '/dashboard/{{name}}/{{name_product_type.type_product|urlencode}}/{{abc}}/';

    $('#postbtn').on('click', function () {
            var $this = $(this),
                data = $this.data();
            $this
                .off('click')
                .text('Abort')
                .on('click', function () {
                    $this.remove();
                    data.abort();
                });
            data.submit().always(function () {
                $this.remove();
            });
        });


$('#fileupload').fileupload({
    url: url,
    crossDomain: false,
    beforeSend: function(xhr, settings) {
        if (!csrfSafeMethod(settings.type)) {
            xhr.setRequestHeader("X-CSRFToken", csrftoken);
        }
    },
    dataType: 'json',
    uploadMultiple: true, // allow multiple upload
    autoProcessQueue: false, // prevent dropzone from uploading automatically
    maxFiles: 5,
    autoUpload: false,
    acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
    maxFileSize: 5000000, // 5 MB
    // 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),
    previewMaxWidth: 100,
    previewMaxHeight: 100,
    previewCrop: true
}).on('fileuploadadd', function (e, data) {
    data.context = $('<div/>').appendTo('#files');
    $.each(data.files, function (index, file) {
        var node = $('<p/>')
                .append($('<span/>').text(file.name));
        if (!index) {
            node
                .append('<br>')
               // .append($('#postbtn').clone(true).data(data));
        }
        node.appendTo(data.context);

    });
}).on('fileuploadprocessalways', function (e, data) {
    var index = data.index,
        file = data.files[index],
        node = $(data.context.children()[index]);
    if (file.preview) {
        node
            .prepend('<br>')
            .prepend(file.preview);
    }
    if (file.error) {
        node
            .append('<br>')
            .append(file.error);
    }
    if (index + 1 === data.files.length) {
        data.context.find($('#postbtn').data(data));
          //  .text('Upload')
           // .prop('disabled', !!data.files.error);
    }
}).on('fileuploadprogressall', function (e, data) {
    var progress = parseInt(data.loaded / data.total * 100, 10);
    $('#progress .progress-bar').css(
        'width',
        progress + '%'
    );
}).on('fileuploaddone', function (e, data) {
    $.each(data.result.files, function (index, file) {
        var link = $('<a>')
            .attr('target', '_blank')
            .prop('href', file.url);
        $(data.context.children()[index])
            .wrap(link);
    });
}).on('fileuploadfail', function (e, data) {
    $.each(data.result.files, function (index, file) {
        var error = $('<span/>').text(file.error);
        $(data.context.children()[index])
            .append('<br>')
            .append(error);
    });
}).prop('disabled', !$.support.fileInput)
    .parent().addClass($.support.fileInput ? undefined : 'disabled');
});
        files=request.FILES.getlist('file')