Fix so files size/count limit is verified (client-side) also on drag-n-drop uploads (#5940)

pull/6072/head
Aleksander Machniak 7 years ago
parent 4722563149
commit 5888ce7c28

@ -3,6 +3,7 @@ CHANGELOG Roundcube Webmail
- Improve detection for Egde browser and add pointer event support (#5922) - Improve detection for Egde browser and add pointer event support (#5922)
- Fix bug where pink image was used instead of a thumbnail when image resize fails (#5933) - Fix bug where pink image was used instead of a thumbnail when image resize fails (#5933)
- Fix so files size/count limit is verified (client-side) also on drag-n-drop uploads (#5940)
RELEASE 1.3.1 RELEASE 1.3.1
------------- -------------

@ -4999,6 +4999,7 @@ function rcube_webmail()
this.display_message(this.env.filesizeerror, 'error'); this.display_message(this.env.filesizeerror, 'error');
return false; return false;
} }
if (this.env.max_filecount && this.env.filecounterror && numfiles > this.env.max_filecount) { if (this.env.max_filecount && this.env.filecounterror && numfiles > this.env.max_filecount) {
this.display_message(this.env.filecounterror, 'error'); this.display_message(this.env.filecounterror, 'error');
return false; return false;
@ -8804,7 +8805,8 @@ function rcube_webmail()
this.file_drag_hover(e, false); this.file_drag_hover(e, false);
// prepare multipart form data composition // prepare multipart form data composition
var uri, files = e.target.files || e.dataTransfer.files, var uri, size = 0, numfiles = 0,
files = e.target.files || e.dataTransfer.files,
formdata = window.FormData ? new FormData() : null, formdata = window.FormData ? new FormData() : null,
fieldname = (this.env.filedrop.fieldname || '_file') + (this.env.filedrop.single ? '' : '[]'), fieldname = (this.env.filedrop.fieldname || '_file') + (this.env.filedrop.single ? '' : '[]'),
boundary = '------multipartformboundary' + (new Date).getTime(), boundary = '------multipartformboundary' + (new Date).getTime(),
@ -8833,6 +8835,16 @@ function rcube_webmail()
// inline function to submit the files to the server // inline function to submit the files to the server
var submit_data = function() { var submit_data = function() {
if (ref.env.max_filesize && ref.env.filesizeerror && size > ref.env.max_filesize) {
ref.display_message(ref.env.filesizeerror, 'error');
return;
}
if (ref.env.max_filecount && ref.env.filecounterror && numfiles > ref.env.max_filecount) {
ref.display_message(ref.env.filecounterror, 'error');
return;
}
var multiple = files.length > 1, var multiple = files.length > 1,
ts = new Date().getTime(), ts = new Date().getTime(),
// jQuery way to escape filename (#1490530) // jQuery way to escape filename (#1490530)
@ -8879,6 +8891,9 @@ function rcube_webmail()
continue; continue;
} }
size += f.size;
numfiles++;
// do it the easy way with FormData (FF 4+, Chrome 5+, Safari 5+) // do it the easy way with FormData (FF 4+, Chrome 5+, Safari 5+)
if (formdata) { if (formdata) {
formdata.append(fieldname, f); formdata.append(fieldname, f);

Loading…
Cancel
Save