[尝试使现有的精美上载器v4.2.2实例与IE8一起使用,但是它返回“没有从加载的iframe收到有效消息”。
阅读3.3和3.7 CORS support博客文章-修改了我的.net MVC处理程序,以检测非XHR请求并做出相应反应。在客户端,已经将CORS属性“ expected”设置为true,但是尝试将“ sendCredentials”和“ allowXdr”的组合设置为true,但效果不明显。
[使用Fiddler确认我返回了正确的内容类型(text / html),并且通常的JSON响应后是指向“ iframe.xss.response.js”的有效URL的脚本块-尝试同时托管主网址和上载程序处理程序子域。
在目前的浏览器中,一切仍然运行良好,就像我在尝试支持IE8时似乎缺少了一些明显的东西。
这是我消毒过的JS;
var fupParams = {
userId: 12345,
userKey: 67890
};
var fupInstance = $("#fine-uploader")
.fineUploader({
template: "qq-template",
thumbnails: {
placeholders: {
waitingPath: "/placeholders/waitingPath.gif",
notAvailablePath: "/placeholders/notAvailablePath.gif"
}
},
session: {
endpoint: "//upload.example.com/Upload/List",
params: fupParams
},
request: {
endpoint: "//upload.example.com/Upload/Upload",
params: fupParams
},
failedUploadTextDisplay: {
mode: "custom"
},
deleteFile: {
customHeaders: {},
enabled: true,
endpoint: "//upload.example.com/Upload/Delete",
method: "DELETE",
forceConfirm: true,
params: fupParams
},
validation: {
allowedExtensions: Array("jpg","png")
},
cors: {
expected: true,
sendCredentials: false
},
autoUpload: true,
editFilename: {
enabled: true
},
classes: {
success: "alert alert-success",
fail: "alert alert-error"
},
showMessage: function (message) {
// Simple event handler
}
})
.on("submit", function (event, id, name) {
// Use qq.Promise() to modify fupParams prior to upload
})
.on("submitDelete", function (event, id, name) {
// Use qq.Promise() to modify fupParams prior to delete
})
.on("error", function (event, id, name, errorReason, xhrOrXdr) {
// Simple event handler
})
.on("complete", function (event, id, name, response) {
// Simple event handler
})
.on("sessionRequestComplete", function (event, response, success, xhrOrXdr) {
// Simple event handler
})
.on("deleteComplete", function (event, id, xhrOrXdr, isError) {
// Simple event handler
})
;
包括通过Fiddler捕获的两个上载处理程序响应,首先将成功设置为false,因为我选择的图像太小;
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Headers: Content-Type, cache-control, x-requested-with
Access-Control-Allow-Credentials: false
Date: Tue, 17 Mar 2015 12:47:54 GMT
Content-Length: 204
{
"success": false,
"error": "Minimum upload size is 150 KB, \"Winter.jpg\" was 103 KB"
}<script src="//www.example.com/fineuploader-4.2.2/iframe.xss.response.js"></script>
[IE之后立即获取“ waitingPath.gif”和“ iframe.xss.response.js”,但我没有看到任何自定义错误文本-只是“没有有效消息”错误。
由于图像较大,第二次捕获成功设置为true,并且我们返回了一些自定义参数,结果与上面相同。
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Headers: Content-Type, cache-control, x-requested-with
Access-Control-Allow-Credentials: false
Date: Tue, 17 Mar 2015 12:51:18 GMT
Content-Length: 278
{
"pageList": [],
"name": "Winter 2.JPG",
"uuid": "2563",
"size": 281,
"thumbnailUrl": null,
"pageCount": 0,
"success": true,
"newUuid": "2563"
}<script src="//www.example.com/fineuploader-4.2.2/iframe.xss.response.js"></script>
EDIT:谢谢您的帮助,我的回答或者使用UUID不正确,或者完全丢失了它-最终结果请参见下文。
成功
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Headers: Content-Type, cache-control, x-requested-with
Access-Control-Allow-Credentials: false
Date: Tue, 17 Mar 2015 15:01:57 GMT
Content-Length: 310
{
"pageList": [],
"name": "Winter 2.JPG",
"newUuid": "2567",
"size": 281,
"thumbnailUrl": null,
"pageCount": 0,
"success": true,
"uuid": "6cb9f309-0c38-4a73-aa13-879abbfff008"
}<script src="//www.example.com/addin/fineuploader-4.2.2/iframe.xss.response.js"></script>
失败
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Headers: Content-Type, cache-control, x-requested-with
Access-Control-Allow-Credentials: false
Date: Tue, 17 Mar 2015 15:01:43 GMT
Content-Length: 255
{
"success": false,
"uuid": "61a4e504-4b89-4b67-ad38-df23d7c4a247",
"error": "Minimum upload size is 150 KB, \"Winter.jpg\" was 103 KB"
}<script src="//www.example.com/addin/fineuploader-4.2.2/iframe.xss.response.js"></script>
由于缺少uuid参数,因此无法正确解析第一个响应。第二个响应看起来有些奇怪。 “ 2563”是Fine Uploader在请求中发送的UUID,还是您要为其分配文件的新UUID?您在响应中具有相同值的“ uuid”和“ newUuid”参数。此响应中的UUID必须根据您正在响应的请求匹配文件的UUID。
目前尚不清楚是不是这个问题,但是匹配的“ uuid”和“ newUuid”表明您的代码中有问题或您对此有误解。