diff --git a/frappe/public/js/frappe/file_uploader/FileUploader.vue b/frappe/public/js/frappe/file_uploader/FileUploader.vue index 50040e0a0e..2420cc1bf5 100644 --- a/frappe/public/js/frappe/file_uploader/FileUploader.vue +++ b/frappe/public/js/frappe/file_uploader/FileUploader.vue @@ -284,7 +284,6 @@ const props = defineProps({ max_file_size: null, // 2048 -> 2KB max_number_of_files: null, allowed_file_types: [], // ['image/*', 'video/*', '.jpg', '.gif', '.pdf'], - blocked_file_types: [], // ['image/heic', 'image/tiff'], crop_image_aspect_ratio: null, // 1, 16 / 9, 4 / 3, NaN (free) }), }, @@ -473,7 +472,6 @@ function check_restrictions(file) { let is_correct_type = true; let valid_file_size = true; - let is_unsupported_file_type = check_unsupported_file_type(file); if (allowed_file_types && allowed_file_types.length) { is_correct_type = allowed_file_types.some((type) => { @@ -495,22 +493,12 @@ function check_restrictions(file) { valid_file_size = file.size < max_file_size; } - if (!is_correct_type || is_unsupported_file_type) { + if (!is_correct_type) { console.warn("File skipped because of invalid file type", file); - if (is_unsupported_file_type) { - frappe.show_alert({ - message: __('File "{0}" was skipped because of unsupported file type "{1}"', [ - file.name, - file.type, - ]), - indicator: "orange", - }); - } else { - frappe.show_alert({ - message: __('File "{0}" was skipped because of invalid file type', [file.name]), - indicator: "orange", - }); - } + frappe.show_alert({ + message: __('File "{0}" was skipped because of invalid file type', [file.name]), + indicator: "orange", + }); } if (!valid_file_size) { console.warn("File skipped because of invalid file size", file.size, file); @@ -523,22 +511,8 @@ function check_restrictions(file) { }); } - return is_correct_type && valid_file_size && !is_unsupported_file_type; + return is_correct_type && valid_file_size; } - -function check_unsupported_file_type(file) { - let { blocked_file_types = [] } = props.restrictions; - return blocked_file_types.some((type) => { - if (type.includes("/")) { - if (!file.type) return false; - return file.type.match(type); - } - if (type[0] === ".") { - return file.name.toLowerCase().endsWith(type.toLowerCase()); - } - }); -} - function upload_files(dialog) { if (show_file_browser.value) { return upload_via_file_browser(); diff --git a/frappe/public/js/frappe/form/controls/attach.js b/frappe/public/js/frappe/form/controls/attach.js index 7855f667bc..bf07aa3ed6 100644 --- a/frappe/public/js/frappe/form/controls/attach.js +++ b/frappe/public/js/frappe/form/controls/attach.js @@ -64,13 +64,15 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro } on_attach_doc_image() { this.set_upload_options(); - this.upload_options.restrictions.allowed_file_types = ["image/*"]; - // file types like .heic/.tiff are not supported for preview directly in the browser, so we block the user from uploading them - this.upload_options.restrictions.blocked_file_types = [ - "image/heic", - "image/heif", - "image/tiff", - "image/tif", + this.upload_options.restrictions.allowed_file_types = [ + "image/jpeg", + "image/png", + "image/gif", + "image/webp", + "image/svg+xml", + "image/avif", + "image/bmp", + "image/x-icon", ]; this.file_uploader = new frappe.ui.FileUploader(this.upload_options); } diff --git a/frappe/public/js/frappe/form/controls/attach_image.js b/frappe/public/js/frappe/form/controls/attach_image.js index 91b957afe9..e4308e63fd 100644 --- a/frappe/public/js/frappe/form/controls/attach_image.js +++ b/frappe/public/js/frappe/form/controls/attach_image.js @@ -20,13 +20,15 @@ frappe.ui.form.ControlAttachImage = class ControlAttachImage extends frappe.ui.f } set_upload_options() { super.set_upload_options(); - this.upload_options.restrictions.allowed_file_types = ["image/*"]; - // file types like .heic/.tiff are not supported for preview directly in the browser, so we block the user from uploading them - this.upload_options.restrictions.blocked_file_types = [ - "image/heic", - "image/heif", - "image/tiff", - "image/tif", + this.upload_options.restrictions.allowed_file_types = [ + "image/jpeg", + "image/png", + "image/gif", + "image/webp", + "image/svg+xml", + "image/avif", + "image/bmp", + "image/x-icon", ]; } };