Skip to content
Snippets Groups Projects
Commit 0f5182ce authored by Arnaud Levy's avatar Arnaud Levy
Browse files

Fix file size limit

parent 8b7aae9c
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ class Communication::Block < ApplicationRecord
include Accessible
IMAGE_MAX_SIZE = 5.megabytes
FILE_MAX_SIZE = 100.megabytes
belongs_to :about, polymorphic: true
......
......@@ -12,6 +12,7 @@ remove = t 'admin.communication.blocks.components.file.input.remove'
type="file"
accept="*"
@change="onFileImageChange( $event, <%= model %>, '<%= property %>' )"
data-size-limit="<%= Communication::Block::FILE_MAX_SIZE %>"
:id="<%= dom_id.html_safe %>">
</div>
<div v-if="<%= model %>.<%= property %>.id">
......
......@@ -68,10 +68,17 @@
this.uploadFile(event.target, files[0], object, key);
},
uploadFile(input, file, object, key) {
var size = Math.round(file.size / 1024 / 1024);
var controller = new Vue.DirectUploadController(input, file, this.directUpload.url)
if (file.size > <%= Communication::Block::IMAGE_MAX_SIZE %>) {
alert("<%= t('admin.communication.blocks.alerts.image_is_too_big').html_safe %> (" + size + " Mo > <%= number_to_human_size Communication::Block::IMAGE_MAX_SIZE %>)");
var size = Math.round(file.size / 1024 / 1024),
sizeLimit = <%= Communication::Block::IMAGE_MAX_SIZE %>,
sizeLimitMo = 0,
controller;
if (input.hasAttribute('data-size-limit')) {
sizeLimit = input.getAttribute('data-size-limit');
}
sizeLimitMo = Math.round(sizeLimit / 1024 / 1024);
controller = new Vue.DirectUploadController(input, file, this.directUpload.url);
if (file.size > sizeLimit) {
alert("<%= t('admin.communication.blocks.alerts.file_is_too_big').html_safe %> (" + size + " Mo > " + sizeLimitMo + " Mo)");
return;
}
controller.start(function (blob) {
......
......@@ -151,7 +151,7 @@ en:
communication:
blocks:
alerts:
image_is_too_big: Image is too big!
file_is_too_big: File is too big!
categories:
basic:
label: Basic blocks
......
......@@ -151,7 +151,7 @@ fr:
communication:
blocks:
alerts:
image_is_too_big: L'image est trop grosse !
file_is_too_big: Le fichier est trop lourd !
categories:
basic:
label: Blocs de base
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment