Urgent Help In File Upload

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Urgent Help In File Upload

Ritesh Koickel
Hi,

 

I have a JSP page through which I am calling action class we are using
commons.upload.jar. Iam getting List Empty.

 

sending the sample code for your ready reference.

 

JSP Page

 

<html:form method="post" action="/upload" enctype="multipart/form-data"
scope="session" type="com.myapp.form.MyRequestForm">
<html:file property="myRequestFile"></html:file>

<html:text property ="name">
<html:submit value="Import" ></html:submit>

</html:form>

 

Action Class :-

 

DiskFileUpload upload = new DiskFileUpload();

List items = upload.parseRequest(request);

 

Iterator iter = items.iterator();

FileItem item =null;

while (iter.hasNext()) {

                  item = (FileItem) iter.next();      

                  if (item.isFormField()) {

                        //here i will be getting the file path

                         String name = item.getFieldName();

                         String value = item.getString();

                  }

            }

            byte [] fileData =item.get();

 

 

Note :- Iam getting the List as empty, can you please suggest the
alternative , I have even tried using common.upload1.1jar.

 

 

DiskFileItemFactory factory = new DiskFileItemFactory();

ServletFileUpload upload = new ServletFileUpload(factory);

 

List fileItems = upload.parseRequest(req);

 

 


------------------------------------------------------------
This message contains information from Silicon Valley Bank, or from one of its affiliates, that may be confidential and privileged.  If you are not an intended recipient, please refrain from any disclosure, copying, distribution or use of this information and note that such actions are prohibited.  If you have received this transmission in error, please notify the sender immediately by telephone or by replying to this transmission.  

This message may include indicative rate information relating to one or more products offered through Silicon Valley Bank, or affiliated broker-dealer, SVB Securities. Rates and yields shown are provided for informational purposes only, are not guaranteed, and are subject to market conditions and availability.  Nothing in this communication shall constitute a solicitation or recommendation to buy or sell a particular security.
Nations Cash Reserves, Nations Treasury Reserves, Nations Institutional Cash Reserves, SVB Securities Liquid Reserves, SVB Securities Institutional Liquid Reserves and SVB Securities Horizon Shares are offered through SVB Securities, a registered broker-dealer and non-bank affiliate of Silicon Valley Bank.  Investments in these products require the involvement of a licensed representative of SVB Securities.  Investment products offered through SVB Securities are not insured by the FDIC or any other Federal Government Agency, are not deposits of or guaranteed by Silicon Valley Bank or its affiliates, and may lose value.


============================================================
Reply | Threaded
Open this post in threaded view
|

RE: Urgent Help In File Upload

James Sangster
Try putting this

FileUpload.isMultipartContent( request )

in and see if you are getting multipart content.  It returns boolean, and if
true then the parseRequest method of DiskFileUpload will need to be used,
otherwise you can just use the regular getParameters or whatever method from
the servlet/jsp classes to get the parameters (as if a GET was received).

james


-----Original Message-----
From: Ritesh Koickel [mailto:[hidden email]]
Sent: Wednesday, May 25, 2005 2:14 PM
To: [hidden email]
Subject: Urgent Help In File Upload


Hi,

 

I have a JSP page through which I am calling action class we are using
commons.upload.jar. Iam getting List Empty.

 

sending the sample code for your ready reference.

 

JSP Page

 

<html:form method="post" action="/upload" enctype="multipart/form-data"
scope="session" type="com.myapp.form.MyRequestForm">
<html:file property="myRequestFile"></html:file>

<html:text property ="name">
<html:submit value="Import" ></html:submit>

</html:form>

 

Action Class :-

 

DiskFileUpload upload = new DiskFileUpload();

List items = upload.parseRequest(request);

 

Iterator iter = items.iterator();

FileItem item =null;

while (iter.hasNext()) {

                  item = (FileItem) iter.next();      

                  if (item.isFormField()) {

                        //here i will be getting the file path

                         String name = item.getFieldName();

                         String value = item.getString();

                  }

            }

            byte [] fileData =item.get();

 

 

Note :- Iam getting the List as empty, can you please suggest the
alternative , I have even tried using common.upload1.1jar.

 

 

DiskFileItemFactory factory = new DiskFileItemFactory();

ServletFileUpload upload = new ServletFileUpload(factory);

 

List fileItems = upload.parseRequest(req);

 

 


------------------------------------------------------------
This message contains information from Silicon Valley Bank, or from one of
its affiliates, that may be confidential and privileged.  If you are not an
intended recipient, please refrain from any disclosure, copying,
distribution or use of this information and note that such actions are
prohibited.  If you have received this transmission in error, please notify
the sender immediately by telephone or by replying to this transmission.  

This message may include indicative rate information relating to one or more
products offered through Silicon Valley Bank, or affiliated broker-dealer,
SVB Securities. Rates and yields shown are provided for informational
purposes only, are not guaranteed, and are subject to market conditions and
availability.  Nothing in this communication shall constitute a solicitation
or recommendation to buy or sell a particular security. Nations Cash
Reserves, Nations Treasury Reserves, Nations Institutional Cash Reserves,
SVB Securities Liquid Reserves, SVB Securities Institutional Liquid Reserves
and SVB Securities Horizon Shares are offered through SVB Securities, a
registered broker-dealer and non-bank affiliate of Silicon Valley Bank.
Investments in these products require the involvement of a licensed
representative of SVB Securities.  Investment products offered through SVB
Securities are not insured by the FDIC or any other Federal Government
Agency, are not deposits of or guaranteed by Silicon Valley Bank or its
affiliates, and may lose value.


============================================================


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Urgent Help In File Upload

Martin Cooper
In reply to this post by Ritesh Koickel
You don't actually say this, but it looks like you are using Struts.
In that case, the reason you are getting no items is because Struts
has already done the parsing for you, and has consumed the input
stream. There is nothing left for you to parse.

Since your form bean already has the corresponding fields for the file
and name items, there is no need for you to be doing the parsing -
Struts does it all for you.

Please see the Struts documentation and archives, and send any
follow-up questions to the Struts User mailing list.

--
Martin Cooper


On 5/25/05, Ritesh Koickel <[hidden email]> wrote:

> Hi,
>
>
>
> I have a JSP page through which I am calling action class we are using
> commons.upload.jar. Iam getting List Empty.
>
>
>
> sending the sample code for your ready reference.
>
>
>
> JSP Page
>
>
>
> <html:form method="post" action="/upload" enctype="multipart/form-data"
> scope="session" type="com.myapp.form.MyRequestForm">
> <html:file property="myRequestFile"></html:file>
>
> <html:text property ="name">
> <html:submit value="Import" ></html:submit>
>
> </html:form>
>
>
>
> Action Class :-
>
>
>
> DiskFileUpload upload = new DiskFileUpload();
>
> List items = upload.parseRequest(request);
>
>
>
> Iterator iter = items.iterator();
>
> FileItem item =null;
>
> while (iter.hasNext()) {
>
>                   item = (FileItem) iter.next();
>
>                   if (item.isFormField()) {
>
>                         //here i will be getting the file path
>
>                          String name = item.getFieldName();
>
>                          String value = item.getString();
>
>                   }
>
>             }
>
>             byte [] fileData =item.get();
>
>
>
>
>
> Note :- Iam getting the List as empty, can you please suggest the
> alternative , I have even tried using common.upload1.1jar.
>
>
>
>
>
> DiskFileItemFactory factory = new DiskFileItemFactory();
>
> ServletFileUpload upload = new ServletFileUpload(factory);
>
>
>
> List fileItems = upload.parseRequest(req);
>
>
>
>
>
>
> ------------------------------------------------------------
> This message contains information from Silicon Valley Bank, or from one of its affiliates, that may be confidential and privileged.  If you are not an intended recipient, please refrain from any disclosure, copying, distribution or use of this information and note that such actions are prohibited.  If you have received this transmission in error, please notify the sender immediately by telephone or by replying to this transmission.
>
> This message may include indicative rate information relating to one or more products offered through Silicon Valley Bank, or affiliated broker-dealer, SVB Securities. Rates and yields shown are provided for informational purposes only, are not guaranteed, and are subject to market conditions and availability.  Nothing in this communication shall constitute a solicitation or recommendation to buy or sell a particular security.
> Nations Cash Reserves, Nations Treasury Reserves, Nations Institutional Cash Reserves, SVB Securities Liquid Reserves, SVB Securities Institutional Liquid Reserves and SVB Securities Horizon Shares are offered through SVB Securities, a registered broker-dealer and non-bank affiliate of Silicon Valley Bank.  Investments in these products require the involvement of a licensed representative of SVB Securities.  Investment products offered through SVB Securities are not insured by the FDIC or any other Federal Government Agency, are not deposits of or guaranteed by Silicon Valley Bank or its affiliates, and may lose value.
>
>
> ============================================================
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]