How do you display an error message from the server when uploading a file fails?

I have a simple uploader with an onFileUploadError handler.

I want to be able to display the error message in the response.

The docs say that the handler takes two parameters file and response[0]. It seems file is a property of the first parameter.

The docs also say that the response needs to be "{ status:'error' }". The event seems to trigger for any response with a 400 status code.

No matter what I have tried response.status is error, even when I set it to client.

How do you get the actual response data? I thought I could have a response like

{ status:'error', message: 'my error message' }

and a handler like

{
  view: "uploader",
  value: "Select File",
  upload: shared.apiUrl + "/api/upload/",
  formData: {},
  // Submit the form when a file is selected
  autosend: true,
  on: {
    onFileUpload: function(response){
      webix.alert("File Uploaded.");
    },
    onFileUploadError: function(response){
      webix.alert("Upload failed. " + response.message);
    }
  }
},

How do you display an error message from the server when uploading a file fails?

0: https://docs.webix.com/api__ui.uploader_onfileuploaderror_event.html

Tagged:

Comments

  • Okay the response from the server is in response.xhr.response.

    {
              localId: "upload",
              view: "uploader",
              value: "Select File",
              upload: shared.apiUrl + "/api/upload/",
              datatype: "json",
              formData: {},
              autosend: true, // Submit the form when a file is selected
              on: {
                onFileUpload: function(response){
                  webix.alert("File Uploaded.");
                },
                onFileUploadError: function(response){
                  let jsonData = JSON.parse(response.xhr.response);
                  webix.alert("Upload failed. " + jsonData.message);
                }
              }
            }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion