From 74a5e92d4652955d7c03409cfe1e668bc8809689 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 21 Nov 2012 11:43:29 +0100 Subject: [PATCH] [FIX] Binary fields, limit upload size to 25Mo (only works for browsers supporting FileAPI) bzr revid: fme@openerp.com-20121121104329-5aa88lxqogn206l2 --- addons/web/static/src/js/view_form.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index ac54df69309..c737282a460 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -4791,6 +4791,7 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(instance. this._super(field_manager, node); this.binary_value = false; this.useFileAPI = !!window.FileReader; + this.max_upload_size = 25 * 1024 * 1024; // 25Mo if (!this.useFileAPI) { this.fileupload_id = _.uniqueId('oe_fileupload'); $(window).on(this.fileupload_id, function() { @@ -4816,6 +4817,11 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(instance. if ((this.useFileAPI && file_node.files.length) || (!this.useFileAPI && $(file_node).val() !== '')) { if (this.useFileAPI) { var file = file_node.files[0]; + if (file.size > this.max_upload_size) { + var msg = _t("The selected file exceed the maximum file size of %s."); + instance.webclient.notification.warn(_t("File upload"), _.str.sprintf(msg, instance.web.human_size(this.max_upload_size))); + return false; + } var filereader = new FileReader(); filereader.readAsDataURL(file); filereader.onloadend = function(upload) {