Using jQuery File Upload (UI version) with a custom server-side upload handler
正常的返回结果,即上传文件成功
Extend your custom server-side upload handler to return a JSON response akin to the following output:
{"files": [
{
"name": "picture1.jpg",
"size": 902604,
"url": "http://example.org/files/picture1.jpg",
"thumbnailUrl": "http://example.org/files/thumbnail/picture1.jpg",
"deleteUrl": "http://example.org/files/picture1.jpg",
"deleteType": "DELETE"
},
{
"name": "picture2.jpg",
"size": 841946,
"url": "http://example.org/files/picture2.jpg",
"thumbnailUrl": "http://example.org/files/thumbnail/picture2.jpg",
"deleteUrl": "http://example.org/files/picture2.jpg",
"deleteType": "DELETE"
}
]}
上传失败,出现错误
To return errors to the UI, just add an error property to the individual file objects:
{"files": [
{
"name": "picture1.jpg",
"size": 902604,
"error": "Filetype not allowed"
},
{
"name": "picture2.jpg",
"size": 841946,
"error": "Filetype not allowed"
}
]}
删除文件
When removing files using the delete button, the response should be like this:
{"files": [ { "picture1.jpg": true }, { "picture2.jpg": true } ]}
Note that the response should always be a JSON object containing a files array even if only one file is uploaded.
Visit the uploaded directory - you should see the same file upload interface as in the demo, allowing you to upload files to your website.