vue-filepond: Is it possible to change error message?

image

I tried to change onerror in server options but it didnt work:

setOptions({
    server: {
        url: '/admin/upload',
        process: {
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
            },
            onerror: res => {
                debugger
                return '123'
            },
        },
    },
})
Environment Version
OS Windows 10
Browser Google Chrome 68.0.3440.106

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 16

Most upvoted comments

const inputElement = document.querySelector('input[type="file"]');
const pond = FilePond.create(inputElement);
let serverResponse = '';
pond.setOptions({
    server: {
        process: {
            url: '/upload',
            onerror: (response) => {
                // I am returning JSON from the backend e.g '{"message": "upload the right documents"}'
                serverResponse = JSON.parse(response);
            }
        },
        revert: '/upload/revert',
        headers: {
            'Accept': 'application/json',
            'X-CSRF-TOKEN': '{{ @csrf_token() }}' // laravel csrf token (substitute with your token)
        }
    },
    labelFileProcessingError: () => {
        // replaces the error on the FilePond error label
        return serverResponse.message;
    }
});

Hi, just published version 2.1.0 of the core filepond library, can you install that instead of 2.0.1.

The onerror callback on the process object should then receive your JSON string {"filepond":["The filepond must be a file of type: audio\/mpeg."]}.

You can now set a function to a label property. The error object received by that function will contain the information returned by the process onerror callback.

labelFileProcessingError: (error) => {
    console.log(error);
    return 'My server errored';
}