Jacob,

That post was all from working examples I had while looking into the problem
(I was curious when I read the original post back then).  Let me know if I
can assist you with anything. Feel free to post your ActionForm and Action
subclasses for assistance.

Regards,
David

-----Original Message-----
From: Jacob Ginu [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 25, 2003 9:30 PM
To: Struts Users Mailing List
Subject: RE: File Upload


David,
No one has got back to me on this except you.There seems to be not much info
regarding this.Iam going throught the link you sent me.
I tried to call MultipartRequestWrapper from an action subclass.I was not
successful in it.

Thanx for your response.

Regards,
Ginu Jacob
David Friedman <[EMAIL PROTECTED]> wrote:
Jacob,

Did anyone ever get back to you on this? Where are you trying to get your
MultiPartRequestWrapper?

In an ActionForm subclass, you can use the method:
getMultipartRequestHandler()

In an Action subclass, you can do pull it from above using:
MultipartRequestWrapper multiWrapper = (MultipartRequestWrapper)
form.getMultipartRequestHandler();

OR, if there is no ActionForm defined for your Action subclass, create a new
type of MultipartRequestHandler such as:

CommonsMultipartRequestHandler cmrh = new CommonsMultipartRequestHandler();
cmrh.setServlet(servlet);
cmrh.handleRequest(request);
HashTable h = cmrh.getFileElements();

I used CommonsMultipartRequestHandler in my example (from an old post) but
any appropriate MultiPartRequestHandler subclass should work.
http://www.mail-archive.com/[EMAIL PROTECTED]/msg87269.html

Just remember 2 things:
a) only one file can be uploaded per file input field - someone tried to
list many files in one upload field and kept seeing Exceptions thrown.

b) if you are not using an ActionForm, there doesn't appear to be a
MultiPartRequestHandler initialized, so create a new one like #2 above.

Regards,
David

-----Original Message-----
From: Jacob Ginu [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 23, 2003 10:03 PM
To: Struts Users Mailing List
Subject: RE: File Upload


Hi,

This is the sample code I am using in the action.java file.I have the
necessary struts file.But it says Unable to find ServletActionContext in
MultipartRequestWrapper when compiled.

MultipartRequestWrapper multiWrapper =
(MultipartRequestWrapper)
ServletActionContext.getRequest();

Enumeration e = multiWrapper.getFileNames();
while(e.hasMoreElements()) {
// get the value of thisinput tag
StringinputValue = (String) e.nextElement();
// get the content type
StringcontentType = multiWrapper.getContentType(inputValue);
// get the name of the file from the input tag
StringfileName = multiWrapper.getFilesystemName(inputValue);
// Get a File object forthe uploaded File
File file = multiWrapper.getFile(inputValue);
// If it's nullthe upload failed
if(file == null) {
addActionError("Error uploading: "+
multiWrapper.getFilesystemName(inputValue));
}


David Friedman wrote:
Why won't you use the struts-upload.war from the Struts distributions?

Regards,
David

-----Original Message-----
From: Jacob Ginu [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 23, 2003 9:48 PM
To: [EMAIL PROTECTED]
Subject: reg:File Upload

Hi,

Can anyone send me a sample file Upload program.

Regards,
Ginu

---------------------------------
Do you Yahoo!?
Yahoo! Photos - Get your photo on the big screen in Times Square


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------
Do you Yahoo!?
Yahoo! Photos - Get your photo on the big screen in Times Square


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------
Do you Yahoo!?
Yahoo! Photos - Get your photo on the big screen in Times Square


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to