Index: openacs-4/packages/file-storage/www/file-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/file-add.tcl,v diff -u -r1.26 -r1.27 --- openacs-4/packages/file-storage/www/file-add.tcl 7 Dec 2018 11:34:52 -0000 1.26 +++ openacs-4/packages/file-storage/www/file-add.tcl 7 Dec 2018 11:54:31 -0000 1.27 @@ -38,7 +38,8 @@ set n_bytes [file size ${upload_file.tmpfile}] set max_bytes [fs::max_upload_size] if { $n_bytes > $max_bytes } { - ad_complain "Your file is larger than the maximum file size allowed on this system ([util_commify_number $max_bytes] bytes)" + set number_of_bytes $max_bytes ; # needed by message key + ad_complain [_ file-storage.lt_Your_file_is_larger_t] } } } @@ -65,16 +66,33 @@ } set context [fs_context_bar_list -final $page_title $folder_id] +set max_upload_size [fs::max_upload_size] ad_form -html { enctype multipart/form-data } \ -export { folder_id lock_title_p name return_url } \ -form { file_id:key {upload_file:file {label "#file-storage.Upload_a_file#"} {html "size 30"} + {help_text "[_ file-storage.Upload_Limit]: $max_upload_size"} } } +# Try to prevent upload of too big files from the client side. Saves +# us some useless requests and gives a quicker feedback to the user. +set number_of_bytes $max_upload_size ; # needed by message key +set file_too_big_msg [_ file-storage.lt_Your_file_is_larger_t] +template::add_event_listener -event submit -id file-add \ + -preventdefault=false -script [subst -nocommands { + var uploadFileField = this.elements.namedItem('upload_file'); + var uploadFile = uploadFileField.files[0]; + if (uploadFile != undefined && + uploadFile.size > $max_upload_size) { + alert('$file_too_big_msg'); + event.preventDefault(); + } +}] + if {[parameter::get -parameter AllowTextEdit -default 0]} { if {[ad_form_new_p -key file_id]} { # To allow the creation of files