implement file size upload limit

This commit is contained in:
Jakob Ketterl
2021-04-29 18:18:18 +02:00
parent 7115d5c951
commit af553c422d
4 changed files with 75 additions and 17 deletions

View File

@ -6,6 +6,7 @@ $.fn.imageUpload = function() {
var originalUrl = $img.prop('src');
var $input = $(this).find('input');
var id = $input.prop('id');
var maxSize = $(this).data('max-size');
$uploadButton.click(function(){
$uploadButton.prop('disabled', true);
var input = document.createElement('input');
@ -14,9 +15,20 @@ $.fn.imageUpload = function() {
input.onchange = function(e) {
var reader = new FileReader()
// TODO: implement file size check
reader.readAsArrayBuffer(e.target.files[0]);
reader.onprogress = function(e) {
if (e.loaded > maxSize) {
console.error('maximum file size exceeded, aborting file upload');
$uploadButton.prop('disabled', false);
reader.abort();
}
};
reader.onload = function(e) {
if (e.loaded > maxSize) {
console.error('maximum file size exceeded, aborting file upload');
$uploadButton.prop('disabled', false);
return;
}
$.ajax({
url: '/imageupload?id=' + id,
type: 'POST',