Passing the error message to jQuery File Upload

前端 未结 3 1326
伪装坚强ぢ
伪装坚强ぢ 2021-02-02 14:44

I\'ve integrated JQuery File Upload into a Java Spring application. The returned JSON is generated from an array of Picture, where Picture contains \"name\", \"size\", \"url\",

相关标签:
3条回答
  • 2021-02-02 15:09
    done: function (e, data){
        var files = data.jqXHR.responseJSON.files;
        console.log(files);
    }),
    

    Each "files" object can have an error var you can work with, like user stivlo said.

    0 讨论(0)
  • 2021-02-02 15:14

    By looking at the source code (the ultimate documentation), I found out that File Upload checks an "error" field and displays that error. I tried and it works, my error gets displayed.

    The JSON response is an array of Objects, one per file uploaded. In case of error, don't fill URLs and size. The important properties are the error and name and size, that will be displayed to the user.

    [ 
        {
            "error": "Image must be in JPG format",
            "url": "", 
            "thumbnail_url": "", 
            "delete_url": "", 
            "delete_type": "DELETE", 
            "name": "broken_image.jpg", 
            "size": 78191
         }
    ]
    
    0 讨论(0)
  • 2021-02-02 15:18

    You can use data.jqXHR.responseText

    Like this:

    fail: function(e, data){
        console.log(data.jqXHR.responseText);
    },
    
    0 讨论(0)
提交回复
热议问题