我使用jQuery File Upload插件调用Web服务并将图像上传到服务器。
图片上传很好,我已经为Web服务添加了一些验证,如果图片大于4MB,则会抛出异常。
以下是我使用文件上传插件的方法:
var fileUploadInput = $('#uploader').fileupload({
dataType: 'json',
add: function (e, data) {
mainObject._addFile(e, data, mainObject);
},
done: function (e, data) {
mainObject._fileUploadDone(e, data, mainObject);
},
fail: function (e, data) {
mainObject._fileUploadFail(e, data, mainObject)
}
});
现在,当文件上传失败时,参数data
包含jqXHR
对象,如下所示:
readyState: 4
status: 200
statusText: "success"
在Chrome中,jqXHR包含由Web服务引发的异常生成的可爱错误消息。在Fiddler中,我可以看到响应是400 Bad Response,我可以在响应正文中看到错误消息。
有谁知道为什么IE8没有被提取?
更新
我们的服务器端代码的简化版本:
[OperationContract(), WebInvoke(UriTemplate = "/Images", Method = "POST")]
public System.Guid CreateImage(System.IO.Stream Image)
{
//IE8 needs response to be in plain text format, or it will attempt to download the response :(
WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-Type", "text/plain");
//perform validation
BLL.Errors validationErrors = BLL.Utilities.ImageFileProcessing.ValidateSizeAndFormat(multipartRequestParser.FileContents);
//if there were errors
if (validationErrors.Count > 0)
{
//send back the errors
throw new WebFaultException<BLL.Errors>(validationErrors, System.Net.HttpStatusCode.BadRequest);
}
//save the image (returns the identifier for the image)
System.Guid imageId = BLL.Custom.BeamUSBuyingWindow.DataTransferObjects.Brand.SaveImage(multipartRequestParser.FileContents);
//set the response status and URI for created resource
WebOperationContext.Current.OutgoingResponse.SetStatusAsCreated(new System.Uri(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.BaseUri.AbsoluteUri + "/" + imageId.ToString()));
return imageId;
}
方法ValidateSizeAndFormat
返回Errors
个对象的数组,其中包含我期待的错误文本。这是一个非常大的应用程序。
我有点感到困惑的是,Chrome在jqXHR对象中发现了400错误,而IE8正在取得200次成功。尽管在其他地方有类似的Ajax错误处理,但这个问题只发生在文件上传插件上。
答案 0 :(得分:0)
对不起我上面的评论,不在服务器端。我仔细阅读了这一页:http://www.checkupdown.com/status/E400.html
我在这里放了一个睁开眼睛,可能是你的眼睛的句子:)
Do you get the error using more than one browser ?. If you have two or more Web browsers installed on your PC and the behaviour is not the same (one Web browser gives an HTTP 400 error visiting a site, another Web browser does not give the 400 error visiting the same site), then one of your browsers may be defective. Try to find an upgrade or security fix for the problem browser. If you recently changed some configuration options in the problem browser, try reversing the change to see if that helps.
请同时阅读该页面的其他内容。