Hello Masters,
I met a very difficult problem.That is I want to upload a file , and Before the server doing real upload work, Some validation to make sure there is no harmful script in the file should be done.
One point is that the real upload work will be done by the classes in a package,in which I'm now allowed to change anything.
In
JSP file, the form's defination is as following:
<FORM NAME="frmInitAttach" METHOD = "POST" ACTION="<%=basePath%>/UploadFileValidation?appid=<%=Constants.STR_FRAMEWORK_APPID%>&this_url=<%= basePath2 %>"ENCTYPE = "multipart/form-data">
<INPUT TYPE="FILE" SIZE="30" NAME="fileInitAttachment" CLASS="f2">
</FORM>
In
Servlet, I first read content from InputStream and then doing some validating operation. This part works OK.But when I complete validating and call the servlet in package to do real upload operation. There is an error occurs :"java.io.IOException: Corrupt form data: no leading boundary". If I remove the part of reading content from InputStream to do validationmentioned above, The whole upload process works OK.So I don't know why.But one thing is certain, in real uploading operation, the inputStream is used again.The following is the part of that Servlet(My added part, doing validation).
InputStream in = request.getInputStream();
int total = 0;
int once = 0;
while ((total < 1024) && (once >= 0)) {
once = in1.read(buffer, total, 1024);
total += once;
ss += new
String(buffer).toString();
}
ss += new String(buffer).toString();
in1.close();
boolean isValid = testFile(ss);
If I remove the above part, There is no Exeption being thrown and whole upload function works ok.
I hope masters here can help me solve the problem or give me some sound advise.
(Because I'm not a native speaker of English, I hope you can understand what I mean

)
Thank you very much!