0
votes

I implemented this plugin completely stock out of the box with a file limit of 2mb, enforced server side with an error response. It works great.

Then I was asked to up the file size limit to 5mb.

I tried everything I could find to try. I simply can't get the plugin to do anything with a file larger than 4.2mb.

No errors, it just doesn't do anything with a file larger than 4.2mb.

Code as it currently sits:

 $('#fileupload').fileupload({

            type: "POST",

            add: function (e, data) {
                if (files < 5) {

                    var errs = [];
                    var acceptFileTypes = /(\.|\/)(gif|jpe?g|png)$/i;
                    var maxFileSize = 5242880;

                    // Validate file
                    $.each(data.files, function (index, file) {
                        if (file.type.length && !acceptFileTypes.test(file.type)) {
                            errs.push('Selected file "' + file.name + '" is not alloawed. Invalid file type.');
                        }
                        if (this['size'] > maxFileSize) {
                            errs.push('Selected file "' + file.name + '" is too big, ' + parseInt(file.size / 1024 / 1024) + 'M.. File should be smaller than ' + parseInt(maxFileSize / 1024 / 1024) + 'M.');
                        }
                    });

                    // Output errors or submit data
                    if (errs.length > 0) {
                        alert('An error occured. ' + errs.join(" "));
                    } else {
                        data.context = $('<p/>').text('Uploading...').appendTo($('.currUploadDiv ul'));
                        data.submit();
                        removeFileUploadLabel();
                        files++;
                        if (files > 0) {
                            $('.fileName').html(files + ' of 5 uploads selected.')
                        } else {
                            $('.fileName').html('Select a file.');
                        }
                    }


                    //data.submit();

                   // return;
                } else {
                    $('.fileName').html('Maximum number of files selected.');
                };
            },
            success: function (e, data) {
                //ToDo- check response for too many files uploaded.


            },
            done: function (e, data) {

                data.context.text(data["_response"]["result"]["message"]);
            },
            error: function (e, data) {
                console.log(e);
            }
        });

I've included the necessary .js files in the proper order (as indicated by a previous answer about MaxFileSize...)

What am I missing?

1

1 Answers

0
votes

This is intentionally by design I'm afraid, the following is from the plugin FAQ: -

What is the maximum file size limitation?

It is possible to upload files up to 4 GB with the jQuery File Upload plugin. By making use of Chunked file uploads (with chunks smaller than 4GB), the potential file size is unlimited. The restriction of 4 GB is due to some browser limitations, which might be fixed in future updates to those browsers.

https://github.com/blueimp/jQuery-File-Upload/wiki/Frequently-Asked-Questions

So what you need is to upload your file in chunks. You can set the chunk size using the maxChunkSize option like this: -

$('#fileupload').fileupload({
    maxChunkSize: 10000000 // 10 MB
});

Be aware that this won't work on all browsers (older versions of IE I'm looking at you!)

See the link below for help with this.

https://github.com/blueimp/jQuery-File-Upload/wiki/Chunked-file-uploads