1 /* SPDX-License-Identifier: CC0-1.0 */
3 function humanize_size(bytes) {
4 if (Math.abs(bytes) < 1024) {
7 const units = [' KiB', ' MiB', ' GiB'];
13 } while (Math.round(Math.abs(bytes) * r) / r >= 1024 &&
14 u < units.length - 1);
15 return bytes.toFixed(1) + units[u];
18 const uploadField = document.getElementById("fileupload");
19 uploadField.onchange = function() {
20 if (this.files[0].size > max_file_size) {
21 alert(`File size ${humanize_size(this.files[0].size)} ` +
22 `exceeds ${humanize_size(max_file_size)}. ` +
23 `Either submit a smaller file, ` +
24 `or use a file hosting service and submit the URL.`);