File Upload Validation - Custom Messages

Hello, so I came across an issue to validate a file and I’m stuck on the part that I need to create a custom message.

Here below is the piece of the code:

'use strict'

const Antl = use('Antl');
const { formatters } = use('Validator');

class StoreDoctor {
    get rules () {
        return {
          crm_image: 'required|file_ext:png,jpg|file_size:2mb',

    get validateAll () {
        return true;

    get messages () {
        return {
            'crm_image.required': 'Imagem Obrigatória',
            'crm_image.file_ext': 'Imagem em formato inválido',
            'crm_image.file_size': 'Tamanho máximo 2BM',


module.exports = StoreDoctor

So when I tried to post the data without the file, the required rule works fine and shows the correct message that I added on the get messages() method: Imagem obrigatória.

Then I selected a file that is a ZIP file just to check if the message that is returning is the same of the method get message(), in this case it should return Imagem em formato inválido, however the message that is returning is a default from the framework Invalid file extension zip. Only png, jpg are allowed.

The same issue is happening for the file size.

So how can I overwrite those the messages for the image format and file size?


1 Like