You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by manish <ma...@npi.stpn.soft.net> on 2002/06/04 11:07:40 UTC

How to upload a file???

Hello All,
    How can I upload a file from browser to server using cocoon.
I am using the following syntax...
<form name = "test" ENCTYPE="multipart/form-data" >

please let me know how to include this tag on cocoon side to accept file
type data

from
anurag


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: How to upload a file???

Posted by Andrew Timberlake <an...@ddd.co.za>.
Anurag

In Cocoon's default state it should already handle the uploads
transparently for you.
Cocoon has two RequestWrappers which handle all uploads and save the
files to a location which by default is (Assuming Tomcat)
<tomcat dir>/Work/Standalone/localhost/cocoon/cocoon-files/upload-dir
You can configure this directory in cocoon.xconf within your WEB-INF
directory.

To access the uploaded files you can retrieve the files through the
request.get(<file's name attribute>) which returns a FilePart object.
You can then use the FilePart object to get the InputStream or other
information.

This was rather rushed so please let me know if you'd like more
information.
You can also see the upload.xsp sample which allows shows you how to
access the upload-dir itself.

PS. The files which are saved during upload are not deleted, you might
want to make sure that all code which handles uploads cleans up
correctly.

Andrew

On Tue, 2002-06-04 at 11:07, manish wrote:
> Hello All,
>     How can I upload a file from browser to server using cocoon.
> I am using the following syntax...
> <form name = "test" ENCTYPE="multipart/form-data" >
> 
> please let me know how to include this tag on cocoon side to accept file
> type data
> 
> from
> anurag
> 
> 
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> 
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
> 
> 
-- 
Andrew Timberlake
Digital Design Development
http://www.ddd.co.za
mailto:andrew@ddd.co.za
011 705 1737
082 415 8283

"If debugging is the process of removing bugs, 
then programming must be the process of putting them in."


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: How to upload a file???

Posted by Andrew Timberlake <an...@timberlake.co.za>.
Anurag

In Cocoon's default state it should already handle the uploads
transparently for you.
Cocoon has two RequestWrappers which handle all uploads and save the
files to a location which by default is (Assuming Tomcat)
<tomcat dir>/Work/Standalone/localhost/cocoon/cocoon-files/upload-dir
You can configure this directory in cocoon.xconf within your WEB-INF
directory.

To access the uploaded files you can retrieve the files through the
request.get(<file's name attribute>) which returns a FilePart object.
You can then use the FilePart object to get the InputStream or other
information.

This was rather rushed so please let me know if you'd like more
information.
You can also see the upload.xsp sample which allows shows you how to
access the upload-dir itself.

PS. The files which are saved during upload are not deleted, you might
want to make sure that all code which handles uploads cleans up
correctly.

Andrew

On Tue, 2002-06-04 at 11:07, manish wrote:
> Hello All,
>     How can I upload a file from browser to server using cocoon.
> I am using the following syntax...
> <form name = "test" ENCTYPE="multipart/form-data" >
> 
> please let me know how to include this tag on cocoon side to accept file
> type data
> 
> from
> anurag
> 
> 
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> 
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
> 
> 


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


RE: How to upload a file???

Posted by Christopher Watson <c....@zen.co.uk>.
Manish

> -----Original Message-----
> From: manish [mailto:manishj@npi.stpn.soft.net]
> Sent: 04 June 2002 10:08
> To: cocoon-users@xml.apache.org
> Subject: How to upload a file???
>
>
> Hello All,
>     How can I upload a file from browser to server using cocoon.
> I am using the following syntax...
> <form name = "test" ENCTYPE="multipart/form-data" >

There's an example bundled with cocoon, on my tomcat installation it's at
http://localhost:8080/cocoon/xsp/upload
(cocoon version 2.0.1)

It uses an xsp page which follows. NB, the bit where it 'contextualizes' is
basically to get the upload directory name from web.xml - you may not need
this,
nor may you need the logging it does, but it's there to show you how .

=============================
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsp:page
          language="java"
          xmlns:xsp="http://apache.org/xsp"
          xmlns:xsp-request="http://apache.org/xsp/request/2.0"
          xmlns:xsp-response="http://apache.org/xsp/response/2.0"
      xmlns:log="http://apache.org/xsp/log/2.0"
>
  <xsp:structure>

<xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:i
nclude>

<xsp:include>org.apache.avalon.framework.context.ContextException</xsp:inclu
de>
  </xsp:structure>

  <xsp:logic>
  File uploadDir = null;
  /** Contextualize this class */
  public void contextualize(Context context) throws ContextException {
    uploadDir = (File) context.get(Constants.CONTEXT_UPLOAD_DIR);
  }
  </xsp:logic>

  <page>
   <title>This form allows you upload files</title>
   <content>
     <para>
       <form method="post" enctype="multipart/form-data" action="upload">
         File:  <input type="file" name="uploaded_file" size="50" />
     <p><input type="submit" value="Upload File" /></p>
       </form>
     </para>
     <para>
     <ul>
       <xsp:logic>
        getLogger().debug("Dir=" + uploadDir);
         String[] filelist = uploadDir.list();
         <![CDATA[
         getLogger().debug("List=" + filelist.length);
         for (int i = 0; i < filelist.length; i++) {
            getLogger().debug("File [" + i + "]=" + filelist[i]);
         ]]>
           <li>
             <xsp:expr>filelist[i]</xsp:expr>
           </li>
         <![CDATA[
         }
         ]]>
       </xsp:logic>
     </ul>
     </para>
     <para>Brought to you by Cocoon at <xsp:expr>new
Date()</xsp:expr>.</para>

   </content>
  </page>
</xsp:page>
=============================

>
> please let me know how to include this tag on cocoon side to accept file
> type data
>
> from
> anurag
>
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
>
>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>