I'm using Blueimp jQuery file upload plugin for upload files.
I had no problem in uploading but the option maxFileSize
and acceptFileTypes
do not work.
This is my code:
$(document).ready(function () {
'use strict';
$('#fileupload').fileupload({
dataType: 'json',
autoUpload: false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
maxFileSize: 5000000,
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p style="color: green;">' + file.name + '<i class="elusive-ok" style="padding-left:10px;"/> - Type: ' + file.type + ' - Size: ' + file.size + ' byte</p>')
.appendTo('#div_files');
});
},
fail: function (e, data) {
$.each(data.messages, function (index, error) {
$('<p style="color: red;">Upload file error: ' + error + '<i class="elusive-remove" style="padding-left:10px;"/></p>')
.appendTo('#div_files');
});
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css('width', progress + '%');
}
});
});
if you have multiple file, you use a loop to verify each of the file format, something like this
You could also use an extra function like:
You should include jquery.fileupload-process.js and jquery.fileupload-validate.js to make it work.
This worked for me in chrome, jquery.fileupload.js version is 5.42.3
This works for me in firefox