problem in file upload

P

Pradyut

Hi
i m using the commons file upload with jsp...(http://
commons.apache.org/fileupload/)

My form is : -[/QUOTE]
<input type="submit" value="submit" name="Upload" />
</form>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I m able to retrieve the details using this code...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
try
{

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Upload</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Upload at " +
request.getContextPath () + "</h1>");
boolean isMultipart = ServletFileUpload.isMultipartContent
(request);
if(isMultipart)
{
ServletFileUpload upload = new ServletFileUpload();
/*List items = upload.parseRequest(request);
Iterator iter = items.iterator();

int count = 0;*/
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext())
{
//count++;
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();


if (item.isFormField()) {
out.println("Form field " + name + " with value "
+ Streams.asString(stream) + " detected.");
}
else
{
out.println("File field " + name + " with file
name " + item.getName() + " detected.");
// Process the input stream
}
}
out.println("</body>");
out.println("</html>");
}
}
catch(FileUploadException fue) {
out.print(fue);
}

finally
{
out.close();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
How do i use the "item" object in the else part(not a form field)

to point to a FileItem(org.apache.commons.fileupload.FileItem)

or particularly how do i use to store it to a database blob???

If i use another code for retrieving into FileItem i m getting
exceptions........
DeferredFileOutputStream (probably at the line List /* FileItem */
items = upload.parseRequest(request);)

The code is

------------------------------------------------------------------------------------------------------------------------------------------------------------------------
try {

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet UploadServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet UploadServlet at " +
request.getContextPath () + "</h1>");

out.print("<br> This is a test a<br>");

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload
(factory);



List /* FileItem */ items = upload.parseRequest
(request);
Iterator iter = items.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
out.print("<br> This is a test a<br>");
}
out.println("</body>");
out.println("</html>");


}
catch(FileUploadException fue) {
out.print(fue);
}
catch(ClassCastException cce) {
out.print(cce);
}
catch(NullPointerException npe) {
out.print(npe);
}
catch(Exception e) {
out.print(e);
}
finally {
out.close();
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Thanks
Pradyut
http://pradyut.tk
India
 
M

Mark Space

Pradyut said:
How do i use the "item" object in the else part(not a form field)

to point to a FileItem(org.apache.commons.fileupload.FileItem)

or particularly how do i use to store it to a database blob???

I did a Google search for "stream blob file" and found this:

<http://dn.codegear.com/article/27462>

For FileItemStream, look at the openStream() method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top