0

I have been using Blueimp jQuery File Upload plugin for sometime and everything seems working fine. Few days back i added a fileuploadadd callback to push files data to a global array. The file upload works okay but the re-size option set at client side is not working, the image gets uploaded in orginal size. I need to resize the image to 800X600 max width and and height.

$('#eventForm').fileupload({
                disableImageResize: false,
                //filesContainer: $('div.files'),
                autoUpload: false,
                imageMaxWidth: 800,
                imageMaxHeight: 600,
                previewMaxWidth: 150,
                previewMaxHeight: 150,
                maxFileSize: 5000000,
                acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
                singleFileUploads: false,
                downloadTemplateId: 'event-download',
                uploadTemplateId: 'event-upload',
                uploadTemplate: function(o) { 
                    var rows = $();
                    $.each(o.files, function (index, file) {
                    var row = $('<tr class="template-upload bgWhite fade">' +
                       '<td class="floatl"><span class="preview"></span></td>' +
                       '<td class="dispNone"><p class="name"></p>' +
                       '<div class="error"></div>' +
                       '</td>' +
                       '<td class="dispNone"><p class="size"></p>' +
                       '<div class="progress"></div>' +
                       '</td>' +
                       '<td class="dispNone">' +
                       (!index && !o.options.autoUpload ?
                           '<button class="start" disabled>Start</button>' : '') +
                       (!index ? '<button class="cancel">Cancel</button>' : '') +
                       '</td>' +
                       '</tr>');
                    row.find('.name').text(file.name);
                    row.find('.size').text(o.formatFileSize(file.size));
                    if (file.error) {
                       row.find('.error').text(file.error);
                    }
                    rows = rows.add(row);
                    });
                    return rows;
                },
                // Uncomment the following to send cross-domain cookies:
                //xhrFields: {withCredentials: true},                
                url: jQuery('#site').val() + 'events/upload?4aToken=' + jQuery('#4aToken').val(),
                success: function(data){
                    //do success callback here;
                },
            }).bind('fileuploadsubmit', function(e, data) {
                jQuery('.fileupload-progress').removeClass('display-hide');
                //validate file share status
                    if ((jQuery('#shareCkts').val() == null || jQuery('#shareCkts').val() == '')) {
                        data.context.find('button').prop('disabled', false);
                        jQuery('#updateFrmValdtn_Nostalgia').parent().css('display', 'help-block').removeClass('display-hide');
                        jQuery('#updateFrmValdtn_Nostalgia').html('Please share this Nostalgia Moment to circuits').removeClass('dispNone');
                        return false;
                    }
                    var inputs = data.context.find(':input');
//                    if (inputs.filter('[value=""]').first().focus().length) {
//                        data.context.find('button').prop('disabled', false);
//                        return false;
//                    }
                        data.formData = jQuery('#eventForm').serializeArray();
            }).bind("fileuploadadd", function(e, data){
                filesList = [];
                filesList.push(data.files[0]);

            });

I am sending the files data to server on success of another ajax call using:

jQuery('#eventForm').fileupload('send', {files:filesList});

I searched and found that on using fileuloadadd or add callback the plugin options gets reset. Is there anyway i can specify image re-size options with this work flow.

1 Answer 1

1

By the looks of it you just need to call:

data.submit();

On the data object which appears inside .bind("fileuploadadd"...).

For anyone else reading this - the autoUpload: false, is critical since without that submit() is called automatically.

Sign up to request clarification or add additional context in comments.

1 Comment

Can this answer PLEASE be accepted! The autoUpload: false is the absolute key. The uploadTemplate will never fire if you use the .bind("fileuploadadd"...) event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.