Re: Still having problems with File upload (multipart-formdata)

2003-12-30 Thread Patrick Scheuerer
Brice Ruth wrote:

I'm refactoring (so to speak) my currently working form, which accepts 
an image to be uploaded, to use a DynaValidator(Action?)Form and I'm 
again running into an exception being thrown:
Hi Brice,
I'm also struggling with file uploads at the moment. But I'm stuck at an earlier 
stage than you.
Could you please post some of your code on how to handle the file upload in the 
action class?
I'm having problems to figure out how to write the file to a subdirectory of my 
web application root.

Your help would be highly appreciated!
Thank you, Patrick
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Still having problems with File upload (multipart-formdata)

2003-12-30 Thread Matthias Wessendorf
Hi Patrick,

you want to get the path of /myapp 
like C:\Tomcat\webapps\myapp
or?

that is done with:

String placeString = 
getServlet().getServletContext().getRealPath(/);

in an actionClass.

you now want to store
in placeString\uploaddir
isn´t it?

i wrote an Util-Class which managed the
storage in my action.
one parameter is the formfile the other the placeToStore.
you can get it, if you want...



-Original Message-
From: Patrick Scheuerer [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 30, 2003 1:12 PM
To: Struts Users Mailing List
Subject: Re: Still having problems with File upload (multipart-formdata)


Brice Ruth wrote:

 I'm refactoring (so to speak) my currently working form, which accepts
 an image to be uploaded, to use a DynaValidator(Action?)Form and I'm 
 again running into an exception being thrown:

Hi Brice,
I'm also struggling with file uploads at the moment. But I'm stuck at an
earlier 
stage than you.
Could you please post some of your code on how to handle the file upload
in the 
action class?
I'm having problems to figure out how to write the file to a
subdirectory of my 
web application root.

Your help would be highly appreciated!
Thank you, Patrick


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


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



Re: Still having problems with File upload (multipart-formdata)

2003-12-30 Thread Brice Ruth
Martin Cooper wrote:

Brice Ruth [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 

I'm refactoring (so to speak) my currently working form, which accepts
an image to be uploaded, to use a DynaValidator(Action?)Form and I'm
again running into an exception being thrown:
java.lang.NoClassDefFoundError:
org/apache/commons/fileupload/FileUploadBase$SizeLimitExceededException
   

This usually happens when your container has another copy of (a different
version of) the Commons FileUpload jar file, and you are not putting all of
your application's jar files in your WEB-INF/lib directory, so that the
wrong jar file is being loaded. Just make sure that your web app is
self-contained and you should be fine.
 

Damn, I tracked this down last time, made sure all the JARs were the 
same version, and somehow a different version has crept in again ... 
Jeesh!! I'll have to track down through CVS how this happened ...

--
Brice D. Ruth
Sr. IT Analyst
Fiskars Brands, Inc.
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Still having problems with File upload (multipart-formdata)

2003-12-30 Thread Patrick Scheuerer
Matthias Wessendorf wrote:

Hi Patrick,

you want to get the path of /myapp 
like C:\Tomcat\webapps\myapp
or?
That's exactly what i was trying to do!

in an actionClass
you now want to store
in placeString\uploaddir
isn´t it?
Right again :-)

i wrote an Util-Class which managed the
storage in my action.
one parameter is the formfile the other the placeToStore.
you can get it, if you want...
That would be wonderful! Thank you very much for your help!

Patrick

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


RE: Still having problems with File upload (multipart-formdata)

2003-12-30 Thread Matthias Wessendorf
Hi Patrick,
okay attched is my class

it offers only two methods.
soon more... perhaps ;-)

one stores a form-file to a place, defined in a PROPERTIES-File
under uploadPath-KEY

the other stores the file to a place which is the second-parameter ;-)

both methods are static. The class has only a private Construktor,
so it is final... :-)



With

String placeString = 
getServlet().getServletContext().getRealPath(/);

you get the Path of your Struts-App
like: C:\Tomcat\webapps\myStrutsApp


so you could use the second like:

UploadFile.saveFile(myFormFile, placeString);

your file is then in root.

hope this is what you needed.

greetings

matthias

-Original Message-
From: Patrick Scheuerer [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 30, 2003 5:15 PM
To: Struts Users Mailing List
Subject: Re: Still having problems with File upload (multipart-formdata)


Matthias Wessendorf wrote:

 Hi Patrick,
 
 you want to get the path of /myapp
 like C:\Tomcat\webapps\myapp
 or?

That's exactly what i was trying to do!

 in an actionClass
 you now want to store
 in placeString\uploaddir
 isn´t it?

Right again :-)

 i wrote an Util-Class which managed the
 storage in my action.
 one parameter is the formfile the other the placeToStore.
 you can get it, if you want...

That would be wonderful! Thank you very much for your help!

Patrick


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

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

Re: Still having problems with File upload (multipart-formdata)

2003-12-30 Thread David Erickson
construktor ;P

- Original Message - 
From: Matthias Wessendorf [EMAIL PROTECTED]
To: 'Struts Users Mailing List' [EMAIL PROTECTED]
Sent: Tuesday, December 30, 2003 9:29 AM
Subject: RE: Still having problems with File upload (multipart-formdata)


Hi Patrick,
okay attched is my class

it offers only two methods.
soon more... perhaps ;-)

one stores a form-file to a place, defined in a PROPERTIES-File
under uploadPath-KEY

the other stores the file to a place which is the second-parameter ;-)

both methods are static. The class has only a private Construktor,
so it is final... :-)



With

String placeString =
getServlet().getServletContext().getRealPath(/);

you get the Path of your Struts-App
like: C:\Tomcat\webapps\myStrutsApp


so you could use the second like:

UploadFile.saveFile(myFormFile, placeString);

your file is then in root.

hope this is what you needed.

greetings

matthias

-Original Message-
From: Patrick Scheuerer [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 30, 2003 5:15 PM
To: Struts Users Mailing List
Subject: Re: Still having problems with File upload (multipart-formdata)


Matthias Wessendorf wrote:

 Hi Patrick,

 you want to get the path of /myapp
 like C:\Tomcat\webapps\myapp
 or?

That's exactly what i was trying to do!

 in an actionClass
 you now want to store
 in placeString\uploaddir
 isn´t it?

Right again :-)

 i wrote an Util-Class which managed the
 storage in my action.
 one parameter is the formfile the other the placeToStore.
 you can get it, if you want...

That would be wonderful! Thank you very much for your help!

Patrick


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








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


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



RE: Still having problems with File upload (multipart-formdata)

2003-12-30 Thread Matthias Wessendorf
and nothing attched:


so see below

Greetings matthias

---
package net.wessendorf.utils.file;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

import org.apache.struts.upload.FormFile;

/**
 * Hilfsklasse, mit welcher aus einer Web-Anwendung
 * Daten zum Web-Server geladen werden können.
 *
 * @author Matthias Wessendorf
 */
public final class UploadFile {

/**
 * 
 * Private Constructor, prevents the class for beeing
 * instanced.
 * 
 *
 */
private UploadFile() {

}

/**
 * 
 * Save a Jakarta FormFile to a preconfigured place.
 * 
 * @param file
 * @return
 */
public static String saveFile(FormFile file){
String retVal = null;

try {
//retrieve the file data
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
InputStream stream = file.getInputStream();
Properties props = new Properties();

//properties must exist

props.load(Thread.currentThread().getContextClassLoader().getResourceAsS
tream(ecards.properties));
String place= props.getProperty(uploadPath);

if(!place.endsWith(/))
place = new
StringBuffer(place).insert(place.length(),/).toString();
retVal = place+file.getFileName();

//write the file to the file specified
OutputStream bos = new FileOutputStream(retVal);
int bytesRead = 0;
byte[] buffer = file.getFileData();
while ((bytesRead = stream.read(buffer)) != -1)
{
bos.write(buffer, 0, bytesRead);
}
bos.close();

//close the stream
stream.close();
}
catch (FileNotFoundException fnfe) {
System.out.println(Datei nicht vorhanden);
fnfe.printStackTrace();
}
catch (IOException ioe) {
ioe.printStackTrace();
}



return retVal;
}

/**
 * 
 * Saves a Jakarta FormFile to a desired place.
 * 
 * @param file - the FormFile to store
 * @param place - the desired place for the file
 * @return place of file
 */
public static String saveFile(FormFile file, String place) {
String retVal = null;

try {
//retrieve the file data
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
InputStream stream = file.getInputStream();

if(!place.endsWith(/))
place = new
StringBuffer(place).insert(place.length(),/).toString();

retVal = place+file.getFileName();

//write the file to the file specified
OutputStream bos = new FileOutputStream(retVal);
int bytesRead = 0;
byte[] buffer = file.getFileData();
while ((bytesRead = stream.read(buffer)) != -1)
{
bos.write(buffer, 0, bytesRead);
}
bos.close();

//close the stream
stream.close();
}
catch (FileNotFoundException fnfe) {
System.out.println(File not found);
fnfe.printStackTrace();
}
catch (IOException ioe) {
ioe.printStackTrace();
}



return retVal;
}
}



-Original Message-
From: David Erickson [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 30, 2003 5:37 PM
To: Struts Users Mailing List
Subject: Re: Still having problems with File upload (multipart-formdata)


construktor ;P

- Original Message - 
From: Matthias Wessendorf [EMAIL PROTECTED]
To: 'Struts Users Mailing List' [EMAIL PROTECTED]
Sent: Tuesday, December 30, 2003 9:29 AM
Subject: RE: Still having problems with File upload (multipart-formdata)


Hi Patrick,
okay attched

Re: Still having problems with File upload (multipart-formdata)

2003-12-30 Thread Patrick Scheuerer
This is exactly what i was looking for! Thank you very much for your help Matthias.

Patrick

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


Re: Still having problems with File upload (multipart-formdata)

2003-12-30 Thread Craig R. McClanahan
Quoting Patrick Scheuerer [EMAIL PROTECTED]:

 Matthias Wessendorf wrote:
 
  Hi Patrick,
  
  you want to get the path of /myapp 
  like C:\Tomcat\webapps\myapp
  or?
 
 That's exactly what i was trying to do!
 
  in an actionClass
  you now want to store
  in placeString\uploaddir
  isn´t it?
 
 Right again :-)
 
  i wrote an Util-Class which managed the
  storage in my action.
  one parameter is the formfile the other the placeToStore.
  you can get it, if you want...
 
 That would be wonderful! Thank you very much for your help!
 

I would also offer a couple of cautions about this approach:

* You are not guaranteed that a particular servlet container
  even *has* a concept of a directory in which the web app
  is deployed -- for example, even Tomcat can execute a webapp
  directly from the WAR file.  When you do that, getRealPath()
  returns null instead of a pathname, and your calculations above
  will trigger a NullPointerException.

* Even when you know that your apps are being deployed in unpacked
  directories, uploading things directly into that directory means
  you have to be careful about redeployment when you update the app
  -- the normal behavior of delete the old directory and replace it
  with the new app wipes out any uploaded files.

I would recommend defining a directory somewhere in your server to hold the
uploaded files for a webapp, and then pass the pathname of this directory to
your app as a context init parameter or something like that.  This approach
deals with both of the problems identified above.

 Patrick
 

Craig


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



Still having problems with File upload (multipart-formdata)

2003-12-29 Thread Brice Ruth
I'm refactoring (so to speak) my currently working form, which accepts 
an image to be uploaded, to use a DynaValidator(Action?)Form and I'm 
again running into an exception being thrown:

java.lang.NoClassDefFoundError: 
org/apache/commons/fileupload/FileUploadBase$SizeLimitExceededException

What's going on here?! Also, to get more mileage out of this post, what 
exactly is the difference between a DynaValidatorForm and a 
DynaValidatorActionForm?!

--
Brice D. Ruth
Sr. IT Analyst
Fiskars Brands, Inc.
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Still having problems with File upload (multipart-formdata)

2003-12-29 Thread Martin Cooper

Brice Ruth [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I'm refactoring (so to speak) my currently working form, which accepts
 an image to be uploaded, to use a DynaValidator(Action?)Form and I'm
 again running into an exception being thrown:

 java.lang.NoClassDefFoundError:
 org/apache/commons/fileupload/FileUploadBase$SizeLimitExceededException

This usually happens when your container has another copy of (a different
version of) the Commons FileUpload jar file, and you are not putting all of
your application's jar files in your WEB-INF/lib directory, so that the
wrong jar file is being loaded. Just make sure that your web app is
self-contained and you should be fine.


 What's going on here?! Also, to get more mileage out of this post, what
 exactly is the difference between a DynaValidatorForm and a
 DynaValidatorActionForm?!

I believe the only difference is in the key passed to the Validator. The
former uses the value of the 'name' attribute from struts-config.xml, while
the latter uses the value of the 'path' attribute. (But no, I don't know
when you would choose one over the other. ;)

--
Martin Cooper



 -- 
 Brice D. Ruth
 Sr. IT Analyst
 Fiskars Brands, Inc.




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