I'm uploading Image using JQuery.
I have limited the image to a maximum of 2mb, however when I send an image larger than 2mb, an exception is made saying Maximum request size exceeded.
What I did:
function fileUpload() {
$('#fileupload').fileupload();
$('#fileupload').fileupload('option', {
maxFileSize: 1024 * 1024,
autoupload: true
});
var uploadFinished = function (e, data) {
if (data.files[0].size > 2000000) { // 2mb
$.notify("Faça o upload de uma imagem de até 2MB", "danger");
jqXHR.abort();
return
}
var img = $("#inpLogoNameNew").val();
$("#imgLogo").show();
$("#imgWhite").hide();
$("#imgLogo").attr("src", (data.result.imgx64));
$("#inpLogoNameNew").val(data.result.Name);
if ($("#inpLogoNameOld").val() !== $("#inpLogoNameNew").val() &&
img !== $("#inpLogoNameNew").val() &&
img !== $("#inpLogoNameOld").val()) {
deleteLogo(img);
}
};
$('#fileupload')
.bind('fileuploaddone', uploadFinished);
}
<form id="fileupload" action="@Url.Action("UploadFiles")" method="POST" enctype="multipart/form-data">
<span id="spanUpload" class="btn btn-primary btn-sm fileinput-button"><i class="icon-plus icon-white"></i><span>Foto</span>
<input id="inpLogo" type="file" name="files[]"/>
</span>
</form>