You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Johannes Becker <jo...@hotmail.com> on 2003/10/13 10:05:14 UTC

File Upload With Action

Hi,

I looked at the "FileUploadWithAction" at Wiki 
(http://wiki.cocoondev.org/Wiki.jsp?page=FileUploadWithAction). Since I'm 
not a good programmer, could anyone tell me how to store the file 
permanently on disc?
I found this thread: 
http://archives.real-time.com/pipermail/cocoon-users/2003-September/038914.html
Is this what I need?

Thanks
Jonny

_________________________________________________________________
Schützen Sie Ihren Posteingang vor unerwünschten E-Mails. 
http://www.msn.de/antispam Jetzt Hotmail-Junk-Filter aktivieren!


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File Upload With Action

Posted by Stefan Klein <kl...@web.de>.
Hi Johannes,

take a look at the following bit of code. I use the FilePartArray rather than the FilePart. FilePartArray is a byte array holding the file contents in memory rather than a reference to a file already stored on disc, i.e. the file is not saved automatically and the data will be lost by the end of the request unless you've saved it (as I do below). I think, you also need to set the "autosave-uploads"-parameter in web.xml to false to make this work. 

For more info see http://wiki.cocoondev.org/Wiki.jsp?page=FileUploadsWithCocoon


If you need more info, let me know. 
Stefan


Here's the code:

Request request = ObjectModelHelper.getRequest(objectModel);
FilePartArray filePartArray=(FilePartArray)request.get("uploaded_file");
OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("/your/path/to/file.jpeg")));  // here put filename and where to save it

InputStream in = filePartArray.getInputStream();
byte[] buf = new byte[8*1024];
int length;

while ((length = in.read(buf)) != -1) 
  out.write(buf,0,length)





On Mon, 13 Oct 2003 08:05:14 +0000
Johannes Becker <jo...@hotmail.com> wrote:

> Hi,
> 
> I looked at the "FileUploadWithAction" at Wiki 
> (http://wiki.cocoondev.org/Wiki.jsp?page=FileUploadWithAction). Since I'm 
> not a good programmer, could anyone tell me how to store the file 
> permanently on disc?
> I found this thread: 
> http://archives.real-time.com/pipermail/cocoon-users/2003-September/038914.html
> Is this what I need?
> 
> Thanks
> Jonny
> 
> _________________________________________________________________
> Schützen Sie Ihren Posteingang vor unerwünschten E-Mails. 
> http://www.msn.de/antispam Jetzt Hotmail-Junk-Filter aktivieren!
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org