commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amitrane <protonica...@gmail.com>
Subject Re: [fileupload] Need help for Streaming API processing
Date Tue, 27 Apr 2010 13:52:27 GMT

Here is the call which seemed to work for me, in order to obtain the
inputStream as byte[]::
IOUtils.toByteArray(inputStream)

I came across it while browsing ::
http://poi.apache.org/spreadsheet/quick-guide.html#Images
Check the sample code there [5th line ].


Here is the code snippet, which seems to be working for me::
if(ServletFileUpload.isMultipartContent(request))
	    {
	    	ServletFileUpload upload= new ServletFileUpload();
	    	try {
			 	FileItemIterator fileItemIterator= upload.getItemIterator(request);
			 	
			while(fileItemIterator.hasNext())
			 {
			   FileItemStream fileItemStream=fileItemIterator.next();
			   InputStream inputStream=fileItemStream.openStream();
			    	
			   if(fileItemStream.isFormField())
			    {
			      /* Looks like working ok for form fields*/
                              String
inputStreamToString=Streams.asString(inputStream);
			      //doProcess
			    }
                           else
			    {
                              /* Case for non form fields */  
                              byte[] inputStreamAsBytes=null; 

			      /*Did Not work. Not sure though*/
			      //inputStreamAsBytes=inputStream.toString().getBytes()

			      /*Did Not work . Not sure though*/ 
                             
//inputStreamAsBytes=Streams.asString(inputStream).getBytes()

			      /* Looks like working. Not sure though :) */
                             
inputStreamAsBytes=IOUtils.toByteArray(inputStream)	
			    
                             }
			}
	    	} catch (FileUploadException fue) {
				// TODO Auto-generated catch block
				fue.getMessage();
				fue.printStackTrace();
			}
	    	
	    }
		
Please feel free to edit, rectify &/or comment. Thanks. 
If s 
-- 
View this message in context: http://apache-commons.680414.n4.nabble.com/fileupload-Need-help-for-Streaming-API-processing-tp746703p2067594.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message