1. Bug scenarios
Some browser images failed to be uploaded. System ADVERTISING system A, in which I participate, needs to call the picture API of system B when uploading pictures using system A.
Second, cause analysis
Possible cause 1: Picture server API problem (No)
The first response was that there might be a problem with the company’s image server API, which is deployed on multiple servers, and if a request for an image upload happened to reach the “broken” API server, the image upload would fail. However, the operation personnel captured the log of the picture API and found no error message. Later, we looked at the log and found that every time we called the image API, it returned the normal status code 200.
view plain
copy
?
- Upload file results — — — — — — — — — — {” code “: 200,” MSG “:” success “, “result”}
Upload file results -- -- -- -- -- -- -- -- -- -- {" code ": 200," MSG ":" success ", "result"}Copy the code
At this point, we think it’s probably not the image API, and we have to find something else.
Possible cause 2: After the image upload request reaches the service layer of the advertising system, an exception is thrown (No).
Through checking the logs, we found that some requests for uploading pictures did not reach the service layer of the advertising system at all. The reason is that at some point in time, the operation staff sent a request to upload the image through Google Chrome, but at this point, there was no relevant log. Under normal circumstances, advertising system is a record of the log for tracking.
Possible cause 3: An error is reported because the image upload request does not enter the Web layer of the advertising system. (Yes)
By checking the access log of the company’s log tool, it was found that the server returned the status code of 400 for the picture uploading request sent by XXX.XXX.xxx. That is, the request was invalid. So far, we have analyzed several reasons leading to this problem.
1. Parameter Type Conversion problem (No)
view plain
copy
?
- @RequestMapping(value = “/sourceUpload”, method = RequestMethod.POST)
- @ResponseBody
- public String sourceUpload(@RequestParam(value = “myfiles”) MultipartFile fileField, @RequestParam(value = “httpsFlag”) StringhttpsFlag) {}
@RequestMapping(value = "/sourceUpload", method = RequestMethod.POST)
@ResponseBody
public String sourceUpload(@RequestParam(value = "myfiles") MultipartFile fileField,@RequestParam(value = "httpsFlag") StringhttpsFlag) {}Copy the code
http://image.tingclass.net/statics/js/2012 this is the web layer interface for image uploads. The httpsFlag field is a String, but the JSP sends a number, such as: 0,1,2. No, although the JSP is passing it as a number, it is actually passing it as a “1”,”2″ string, which spring MVC can receive.
2. The httpsFlag parameter was never sent. (Yes)
Later, I started the AD system locally and used my colleague’s browser for remote debugging. I found that the request payload for file uploading on her computer did not contain the httpsFlag field, but only myFiles, as follows:
view plain
copy
?
- payload:
- 02 edition giveaway 02-700×500.jpg
- ————Ij5cH2gL6ei4KM7KM7GI3gL6ei4cH2
- Content-Disposition: form-data; name=”myfiles”; Filename =” version 02 giveaway 02-700×500.jpg”
- Content-Type: application/octet-stream
Content: 02 edition gift 02-700 x500. JPG -- -- -- -- -- -- -- -- -- -- -- -- Ij5cH2gL6ei4KM7KM7GI3gL6ei4cH2 Content - Disposition: the form - data; name="myfiles"; Filename =" version 02 giveaway 02-700x500.jpg" content-type: application/octet-streamCopy the code
Because the httpsFlag parameter was not passed in and the Spring MVC interface requires that it be passed in, the request reached the Spring MVC interceptor and received an error of 400 because the action did not match. Now the question is, why is the httpsFlag field not passed in?
It was found that there was a problem with the open source upload component Swfupload, as follows:
view plain
copy
?
- this.setPostParams({
- ‘httpsFlag’: $(‘#httpsFlag’).val()
- });
this.setPostParams({
'httpsFlag':$('#httpsFlag').val()
}); Copy the code
Swfupload uses the code above to pass parameters, but parameter names must be enclosed in double quotation marks, which can cause problems in some browsers. Change the code to the following form.
view plain
copy
?
- this.setPostParams({
- “httpsFlag”: $(‘#httpsFlag’).val()
- });
this.setPostParams({
"httpsFlag":$('#httpsFlag').val()
}); Copy the code
Payload payload payload payload payload payload payload payload
view plain
copy
?
- payload:
- 330868-14030420415958.jpg
- ————ae0ei4GI3Ij5gL6KM7ae0gL6cH2cH2
- Content-Disposition: form-data; name=”httpsFlag”
- 0
- ————ae0ei4GI3Ij5gL6KM7ae0gL6cH2cH2
- Content-Disposition: form-data; name=”myfiles”; filename=”330868-14030420415958.jpg”
- Content-Type: application/octet-stream
payload:
330868-14030420415958.jpg
------------ae0ei4GI3Ij5gL6KM7ae0gL6cH2cH2
Content-Disposition: form-data; name="httpsFlag"
0
------------ae0ei4GI3Ij5gL6KM7ae0gL6cH2cH2
Content-Disposition: form-data; name="myfiles"; filename="330868-14030420415958.jpg"
Content-Type: application/octet-streamCopy the code
Conclusion:
1. Use log tools provided by the company to help locate problems;
Each request, will go through a number of links, a link a link of the exclusion
When defining web layer interface parameters using Spring MVC, we can add the required = false configuration, so that even if the parameters are not passed in, we can still enter the action interface, and then we can throw relevant information in the action so that the problem can be easily located.
4. The root cause of some browser upload failures is not clear at present. It may be due to browser configuration problems or PC problems.