Problems with flash upload in spring mvc, springmvc
Reprinted Please note:TheViper http://www.cnblogs.com/TheViper
For compatibility purposes, flash (such as swfupload and uploadify) is often used for uploading on the pc side for better user experience.
However, if the background is spring mvc and the browser is IE, the server will not return data to flash, trigger the DataEvent. UPLOAD_COMPLETE_DATA event of FileReference, and execute the callback to make corresponding changes to the page. The strange thing is that in a non-IE browser, flash can get the returned data.
Change the log4j level to debug.
IE
Non-IE
You can see that both of them have received the multipart file content from flash, but IE debug has an HttpMediaTypeNotAcceptableException. In this document, Exception thrown when the request handler cannot generate a response that is acceptable by the client. Now I understand that the response returned by the background is not accepted by flash.
So how did this problem come out?
Fortunately, flash files can be uploaded to the node. js background of the local machine. Next, let's take a look at the header information of the flash upload request under IE.
Not in IE
Note that the accept: 'text/* 'in the header information of IE. The spring mvc background of this plug-in returns json. The most direct method is used. @ RequestMapping (value = "/upload1", produces {"application/json; charset = UTF-8 "}). That is to say the response is Content-Type: application/json; charset = UTF-8. Flash only accepts the response of Content-Type: text/* (text/html, text/xml. For non-IE headers, the accept value is */*, and the content-type value is acceptable for any type of response. For flash, the background response is acceptable.
If you know where the problem is, you can modify it. Here, you can directly change application/json to text /*. if other methods are used to return json or other forms of data, set the content-type of the response to be consistent with the accept of flash. I won't talk about the specifics.
In addition, if you modify the flash source code, it is useless to modify the accept for the uploaded URLRequest. During the upload, the accept is still the default value of flash in different browsers.
var request:URLRequest=new URLRequest('http://localhost:8080/qzone/photo/upload1'); var header:URLRequestHeader = new URLRequestHeader("accept", "application/json"); request.requestHeaders.push(header);