0

I am using Fine Uploader 3.7.0 in a project with Chrome and Firefox and it works fine, but with Internet Explorer 10 the files are uploaded correctly but the user always get the "Upload failed" error message, even with the demo tests:

<script>
$(document).ready(function() {
     var errorHandler = function(event, id, fileName, reason) {
            qq.log("id: " + id + ", fileName: " + fileName + ", reason: " + reason);
        };

    var myUploader = new qq.FineUploader({
        element: $('#basicUploadButton')[0],
        multiple: false,
        callbacks: {
            onError: errorHandler
        },
        request: {
            endpoint: '/fineupload/receiver'
        }
    });
});
</script>
<div class="fineUploader">
    <span>Please upload your files for automated process.</span>
    <div id="basicUploadButton" class="upload-btn"></div>
</div>
<br />
<div><a href="#" onclick="window.close()">Close Window</a></div> 

I debugged the servlet and I see that I am sending this:

writer.print("{\"success\": true, \"uuid\": \"" + requestParser.getUuid() + "\", \"originalFileName\": \"" + requestParser.getFilename() + "\"}");

so I think that the JSON I am supposed to get is correct.

Any ideas why can this be failing with IE10? I also tried with the compatibility modes and didn't work.

Updated: Console log:

[FineUploader 3.7.0] Error when attempting to parse xhr response text (SyntaxError: Invalid character) 
 id: blog.jpg, fileName: Upload failure reason unknown, reason: [object XMLHttpRequest]

Thanks!

4

2 回答 2

1

问题是由于我在 Java 中创建的 JSON 响应。

查看 IE10 开发人员工具中的 Network 选项卡(感谢 Ray 的建议),我得到:

{"error": "java.io.FileNotFoundException: C:\data\uploads\fd9b5240-5661-4f07-a216-7a76b2250b00_C:\folder\blog.jpg (The filename, directory name, or volume label syntax is incorrect)"}

我正在使用

writer.print("{\"success\": true, \"uuid\": \"" + requestParser.getUuid() + "\", \"originalFileName\": \"" + requestParser.getFilename() + "\"}");

取而代之的是

JSONObject json = new org.json.JSONObject();
json.put("success", true);
json.put("uuid", requestParser.getUuid());
json.put("originalFileName", requestParser.getFilename());
writer.print(json.toString());

适用于每个浏览器。

无论如何,我需要避免使用 IE10 管理的文件名 (C:\folder\blog.jpg) 所以我不得不使用

json.put("originalFileName", getCorrectFileName(requestParser.getFilename()));

使用 getCorrectFilename(String s) 删除“C:\folder\”部分。

于 2013-08-07T21:33:07.570 回答
0

“我的文件已发送到服务器,但 Fine Uploader 报告失败”的问题是常见的问题。正如文档所述,您必须在对 Fine Uploader 的上传 POST 请求的响应中返回有效的 JSON。根据您的评论,您没有返回有效的 JSON。要验证您返回的 JSON 是否有效,您可以使用JSON Lint等工具。您可以通过浏览器的开发人员工具检查响应负载,或在 Fine Uploader 选项中设置选项debugtrue

正如@mfeltner 所说,在构建响应时,您应该在服务器端使用 JSON 序列化工具。

于 2013-08-07T14:57:43.247 回答