尝试使现有的精细上传器v4.2.2实例与IE8一起工作,但它返回"没有从加载的iframe接收有效消息"。
通读3.3和3.7 CORS support博客文章 - 修改了我的.net MVC处理程序,以检测非XHR请求并做出相应的反应。在客户端已经有了CORS属性"预期"设置为true,但尝试设置" sendCredentials"的组合和" allowXdr"没有明显的效果。
使用Fiddler确认我正在返回正确的内容类型(text / html),通常的JSON响应之后是一个脚本块,指向" iframe.xss.response.js&的有效URL #34; - 尝试在主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立即取出&#34; waitingPath.gif&#34;和&#34; iframe.xss.response.js&#34;,但我没有看到任何自定义错误文本 - 只是&#34;没有有效的消息&#34;错误。
由于图像较大,第二次捕获成功设置为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>
编辑:感谢您的帮助,我的回复是错误地使用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>
答案 0 :(得分:0)
由于缺少uuid参数,第一个响应未正确解析。第二个回应看起来有点奇怪。是&#34; 2563&#34; Fine Uploader在请求中发送的UUID,或者是您要分配文件的新UUID?你有&#34; uuid&#34;和&#34; newUuid&#34;响应中的参数值具有相同的值。此响应中的UUID必须根据您要响应的请求匹配文件的UUID。
目前尚不清楚是否在这里发布问题,但是匹配&#34; uuid&#34;和&#34; newUuid&#34;表明您的代码中存在问题或您的误解。