将错误消息传递给jQuery文件上传 [英] Passing the error message to jQuery File Upload

查看:92
本文介绍了将错误消息传递给jQuery文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 JQuery文件上传集成到Java Spring应用程序中。返回的JSON由图片数组生成,其中图片包含名称,大小,url,thumbnail_url,delete_url和delete_type。有时我决定不接受在服务器上的上传,拒绝它,因为缺少前提条件,所以我想通知用户有关它,通过返回给客户端一个错误消息。

我知道可能会返回一个错误消息和一个错误代码到文件上传插件,但我找不到在文档中。我想我必须添加两个类似error_message和error_code的字段。



我在哪里可以找到这个文档,或者是我应该返回的字段名称是什么。

解决方案

通过查看源代码(最终文档),我发现文件上载检查错误字段并显示该错误。我尝试了,它的工作原理,我的错误得到显示。



JSON响应是一个对象的数组,每个文件上传一个。如有错误,请不要填写网址和大小。重要的属性是错误名称大小,这将显示给用户。

  [
{
error:Image must be以JPG格式,
url:,
thumbnail_url:,
delete_url:,
delete_type:DELETE,
name:broken_image.jpg,
size:78191
}
]


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", "thumbnail_url", "delete_url" and "delete_type".

Sometimes I decide to not accept the upload on the server, to reject it, because of missing pre-conditions, so I would like to inform inform the user about it, by returning to the client an error message.

I know it's possible to return an error message and an error code to the File Upload plugin, but I can't find it in the documentation. I suppose that I've to add two fields similar to "error_message" and "error_code".

Where can I find this documentation or what are the field names that I should return.

解决方案

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
     }
]

这篇关于将错误消息传递给jQuery文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆