jQuery-File-Upload icon indicating copy to clipboard operation
jQuery-File-Upload copied to clipboard

Is there a way to upload multiple resolutions at the same time?

Open RyanBErickson opened this issue 14 years ago • 6 comments

I love the way you can use client-side resolution scaling, which saves complexity on the back end.

Is there a way to have the upload do the upload with multiple scaled images, of different resolutions?

I'd like to upload 2-3 different resolutions of the image, all doing the scaling on the front end.

Thanks again.

RyanE

RyanBErickson avatar Mar 06 '12 21:03 RyanBErickson

Yes, it's possible. Here's an example code snippet:

$('#fileupload').fileupload({
    submit: function (e, data) {
        var resizeSettings = [
                {resizeMaxWidth: 1280},
                {resizeMaxWidth: 1024},
                {resizeMaxWidth: 800}
            ],
            $this = $(this),
            originalFile = data.files[0],
            filestoSubmit = [],
            deferred = $.Deferred(),
            promise = deferred.promise();
        $.each(resizeSettings, function (index, settings) {
            promise = promise.pipe(function () {
                filestoSubmit.push(data.files[0]);
                data.files = [originalFile];
                $.extend(data, settings);
                return $this.fileupload('resize', data);
            });
        });
        deferred.resolve();
        promise.done(function () {
            filestoSubmit.push(data.files[0]);
            data.files = filestoSubmit;
            $this.fileupload('send', data);
        });
        return false;
    } 
});

Please note that I've updated the Image Processing plugin to allow the code snippet above to work properly.

blueimp avatar Mar 07 '12 19:03 blueimp

Awesome! Thanks for answering this and my other question so quickly. I'll give it a try tonight and close the issues if I can get 'em working.

Thanks again!

RyanBErickson avatar Mar 07 '12 19:03 RyanBErickson

I've added a slightly modified version to the Wiki: https://github.com/blueimp/jQuery-File-Upload/wiki/Upload-multiple-resolutions-of-one-image-with-multiple-resize-options

blueimp avatar Mar 08 '12 09:03 blueimp

hey can you please take a looak at this https://github.com/blueimp/jQuery-File-Upload/issues/1076

vijendrapatil avatar Mar 08 '12 10:03 vijendrapatil

I've added the code to my main.js, and it appears the submit function gets called for each resolution (and the resize method gets called multiple times before the upload), but only a single file gets sent to my upload URL, the original size (after the 'load' resize).

I can't figure out why it's not working, except it appears that in the _resizeImage function, the canvas height and width are always 640x480, so it never calls canvastoblob.

Any ideas? Or could you modify the sample main.js so it does the multiple file uploads?

Thanks for the help.

RyanBErickson avatar Mar 09 '12 17:03 RyanBErickson

Nevermind... It appears it is uploading all the images. duh. :)

My .cgi just isn't looking for them properly.

Thanks agian.

RyanBErickson avatar Mar 09 '12 18:03 RyanBErickson