diff --git a/app/Http/Requests/AnswerFormRequest.php b/app/Http/Requests/AnswerFormRequest.php index 8e381f74..c1f8f9c1 100644 --- a/app/Http/Requests/AnswerFormRequest.php +++ b/app/Http/Requests/AnswerFormRequest.php @@ -27,6 +27,12 @@ class AnswerFormRequest extends FormRequest $this->maxFileSize = $this->form->workspace->max_file_size; } + private function getFieldMaxFileSize($fieldProps) + { + return array_key_exists('max_file_size', $fieldProps) ? + min($fieldProps['max_file_size'] * 1000000, $this->maxFileSize) : $this->maxFileSize; + } + /** * Validate form before use it * @@ -180,7 +186,7 @@ class AnswerFormRequest extends FormRequest if (! empty($property['allowed_file_types'])) { $allowedFileTypes = explode(',', $property['allowed_file_types']); } - $this->requestRules[$property['id'].'.*'] = [new StorageFile($this->maxFileSize, $allowedFileTypes, $this->form)]; + $this->requestRules[$property['id'] . '.*'] = [new StorageFile($this->getFieldMaxFileSize($property), $allowedFileTypes, $this->form)]; return ['array']; case 'email': diff --git a/app/Http/Requests/UserFormRequest.php b/app/Http/Requests/UserFormRequest.php index 7444b525..74660646 100644 --- a/app/Http/Requests/UserFormRequest.php +++ b/app/Http/Requests/UserFormRequest.php @@ -118,6 +118,9 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest 'properties.*.generates_uuid' => 'boolean|nullable', 'properties.*.generates_auto_increment_id' => 'boolean|nullable', + // For file (min and max) + 'properties.*.max_file_size' => 'min:1|numeric', + // Security & Privacy 'can_be_indexed' => 'boolean', 'password' => 'sometimes|nullable', diff --git a/client/components/open/forms/OpenFormField.vue b/client/components/open/forms/OpenFormField.vue index d9738cb5..5c1281f6 100644 --- a/client/components/open/forms/OpenFormField.vue +++ b/client/components/open/forms/OpenFormField.vue @@ -303,7 +303,7 @@ export default { } } else if (field.type === 'files' || (field.type === 'url' && field.file_upload)) { inputProperties.multiple = (field.multiple !== undefined && field.multiple) - inputProperties.mbLimit = this.form?.max_file_size ?? this.currentWorkspace?.max_file_size + inputProperties.mbLimit = Math.min(Math.max(field.max_file_size, 1), this.form?.max_file_size ?? this.currentWorkspace?.max_file_size) inputProperties.accept = (this.form.is_pro && field.allowed_file_types) ? field.allowed_file_types : '' } else if (field.type === 'number' && field.is_rating) { inputProperties.numberOfStars = parseInt(field.rating_max_value) diff --git a/client/components/open/forms/fields/components/FieldOptions.vue b/client/components/open/forms/fields/components/FieldOptions.vue index f65153c2..88d1db59 100644 --- a/client/components/open/forms/fields/components/FieldOptions.vue +++ b/client/components/open/forms/fields/components/FieldOptions.vue @@ -60,6 +60,13 @@ label="Allowed file types" placeholder="jpg,jpeg,png,gif" help="Comma separated values, leave blank to allow all file types" /> + + @@ -428,6 +435,9 @@ export default { required: false } }, + setup() { + return { currentWorkspace: computed(() => useWorkspacesStore().getCurrent), } + }, data () { return { typesWithoutPlaceholder: ['date', 'checkbox', 'files'], @@ -442,6 +452,9 @@ export default { hasPlaceholder () { return !this.typesWithoutPlaceholder.includes(this.field.type) }, + mbLimit() { + return this.form?.max_file_size ?? this.currentWorkspace?.max_file_size + }, prefillSelectsOptions () { if (!['select', 'multi_select'].includes(this.field.type)) return {} @@ -504,6 +517,9 @@ export default { if (['text', 'number', 'url', 'email'].includes(this.field?.type) && !this.field?.max_char_limit) { this.field.max_char_limit = 2000 } + if (this.field.type == 'files') { + this.field.max_file_size = Math.min((this.field.max_file_size ?? this.mbLimit), this.mbLimit) + } }, methods: {