I have a servlet that receives an uploaded file. We are raising problems with the requests of a specific client, in which the file is not attached or the servlet thinks. Upload Servlet is a replacement for an old one and we are using the Apache Commons File Upload Library to parse the file from the request. The old code uses the Java Zoom library. Clients working with clients are working perfectly in the old code.
To troubleshoot the problem, I added a bunch of logging to see the request header and parts which does not work with the client which does not have a snippet that I see which parts I am:
Archive & lt; Part & gt; Parts = request.getParts (); For (part part: parts) {string partName = part.getName (); Log.debug ("part =" + partName); Collections & lt; String & gt; HeaderNames = part.getHeaderNames (); For (string header name: header name) {string header value = part.gate header (header name); Log.debug (headerName + "=" + headerValue); Inputstream inputstream = part.jetInststream (); Buffered Redresser = New Buffettder (new inputstreamer (inputstream, "UTF-8")); Stringbuilder builder = new stringbiller (); {String line = buffed reader.readline (); Line! = Null; Try line = buffed reader.readline ()) {builder.append (line); Builder.append ('\ n'); }} Hold (ignore IOException) {// empty} end {inputStream.reset (); } Log.debug ("InputStream =" + builder.toString ()); }} All this code works fine and I'm hoping for logging. However, the next bit of code does not work as expected:
if (isMultipart) {// Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory (); // Create a new file upload handler: ServletFile Upload Upload = New ServletFileUpload (Factory); @SuppressWarnings ("raw type") list item = null; // Try Parsing Request {items = upload.parseRequest (request); Log.debug ("item =" + item); } Hold (file upload prefix extension) {log. Warne ("error parsing request", formerly); Response. SendError (HTTP Services Response. SC_BAD_REQUEST, former. Messages); } Item variable is empty when it is logged in. If I answer the code to request parts, this bit of code works and the file uploaded in the item variable. I can only assume that reading / reading parts from receipt / request in some way removes it from it and is no longer available for further processing. Is there any way to read them for logging purposes and then keep them in the request for further processing?
Archive & lt; Part & gt; Parts = request.getParts (); is a Savvate 3.0 API which is the replacement for the Commons Apache File Upload API . You should use only one of two ways, both have support for processing with the uploaded files and parameters.
Here is an example
The problem you are experiencing is because you can do this archive & lt; Part & gt; Parts = Request .getParts (); The request will use input input stream. And then you're using the Apache Commons API to read the parts again. Because the stream has already been read, you see that no part is available. Reference for file uploads for a certificate 3.0: -
-
-
Comments
Post a Comment