You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by bosspring 2 <bo...@hotmail.com> on 2003/06/14 16:30:08 UTC

File Uploads

Hi!!

I want upload files in a simple form, but I don´t know to modifie the 
upload-directory because I write "pfc/uploads" in the file web.xml and the 
form doesn't upload.

What is the configuration of the parameters in web.xml? I want to use 
pfc/uploads that upload-directory

Thank you.

Miguel Ángel

_________________________________________________________________
Melodías, logos y mil servicios para tu teléfono en MSN Móviles.  
http://www.msn.es/MSNMovil/


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


Re: File Uploads additional comment

Posted by juliane ndje <ju...@petra-productions.de>.
it works! your 'copy file to correct directory and delete from incoming' 
looked similar to my code and that made me look for the mistake at other 
places... found it.
dankeschön and till next
juliane

Alexander Schatten wrote:

> Alexander Schatten wrote:
>
>>                File from = new File(pdf);
>>                File to  = new File(targetFilename);
>>                from.renameTo(to);
>
>
> I believe, this rename function is only working since JDK 1.4. so if 
> you need to use an earlier version, you have to write this by yourself 
> eventually.
>
>
> alex
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>
>



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


Re: File Uploads additional comment

Posted by Alexander Schatten <al...@gmx.at>.
Alexander Schatten wrote:

>                File from = new File(pdf);
>                File to  = new File(targetFilename);
>                from.renameTo(to);

I believe, this rename function is only working since JDK 1.4. so if you 
need to use an earlier version, you have to write this by yourself 
eventually.


alex


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


Re: File Uploads

Posted by Alexander Schatten <al...@gmx.at>.
juliane ndje wrote:

> hi geoff,
> i've seen the wiki pages and also the FileUploadAction in the 
> Developer's Handbook (Moczar/Aston). my problem is that i don't want 
> to put all the files into one directory but put them into the 
> directory named after a project that is to be choosen in a select 
> field (is that understandable?). there is a directory for every 
> project and the file belongs to exactly one project. therefore the way 
> suggested by alexander seemed quite appealing to me.
> btw i need this for an app written in 2.0.4
> thanx juliane

My solution is basically working like this:

(1) set the parameters in the web.xml (I guess), so that file uploads 
are automatically accepted and enter the path where they should be put to.

(2) I have a form, where you may enter data of a publication (author, 
title, ...) plus a pdf document.

(3) the following xsp gets the pdf filename adds some timestamp to 
ensure, that the filename is unique, than creates a SQL insert and 
inserts the metainformation including filename into the database, then 
moves the PDF from the "general" incoming directory to the desired pdf 
directory:

so this is the xsp. maybe it is helpful for you.

<?xml version="1.0" encoding="iso-8859-1"?>
<xsp:page
    xmlns:xsp="http://apache.org/xsp"
    xmlns:esql="http://apache.org/cocoon/SQL/v2"
    xmlns:xsp-request="http://apache.org/xsp/request/2.0"
    xmlns:xsp-session="http://apache.org/xsp/session/2.0"
    language="java" >

    <xsp:structure>
        <xsp:include>java.io.*</xsp:include>
    </xsp:structure>

   
    <response>
        <xsp:logic>
            <!-- read post parameters -->
            String author    = <xsp-request:get-parameter name="author"/>;
            String title     = <xsp-request:get-parameter name="title"/>;
            String citation  = <xsp-request:get-parameter 
name="citation"/>;
            String category  = <xsp-request:get-parameter name="category"/>;
            String pdf       = <xsp-request:get-parameter name="pdf"/>;
            String pdfpath   = (String)session.getAttribute("pdfpath");
            <!-- extract only filename and drop path -->
            <!-- add timestamp to filename to make it unique -->
            String pdf_fn = "";
            boolean pdfexists = false;
            if ((pdf!=null) &amp;&amp; (pdf.length()>1) ) {
                int lastPath = pdf.lastIndexOf(File.separator)+1;
                pdf_fn = "" + System.currentTimeMillis() + "-" + 
pdf.substring(lastPath);
                pdfexists = true;
            }
            <!-- build SQL INSERT statement for mySQL -->
            String sql = "(author,title,citation,category,pdf) VALUES 
('" + author + "', '" + title + "', '" + citation + "', '" + category + 
"', '" + pdf_fn + "')";       
           
            <!-- copy file to correct directory and delete from incoming -->
            if (pdfexists) {
                String targetFilename = pdfpath + "/" + pdf_fn;
                File from = new File(pdf);
                File to  = new File(targetFilename);
                from.renameTo(to);
            }

        </xsp:logic>
       
        <!-- this part is performed if the data is correct -->
      
        <esql:connection>
            <esql:pool>hermesdb</esql:pool>
            <esql:execute-query>
                <esql:query>INSERT INTO citation 
<xsp:expr>sql</xsp:expr></esql:query>
                <esql:error-results><database_error /></esql:error-results>
            </esql:execute-query>
        </esql:connection>
            <ok />      

    </response>


</xsp:page>


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


Re: File Uploads

Posted by juliane ndje <ju...@petra-productions.de>.
hi geoff,
i've seen the wiki pages and also the FileUploadAction in the 
Developer's Handbook (Moczar/Aston). my problem is that i don't want to 
put all the files into one directory but put them into the directory 
named after a project that is to be choosen in a select field (is that 
understandable?). there is a directory for every project and the file 
belongs to exactly one project. therefore the way suggested by alexander 
seemed quite appealing to me.
btw i need this for an app written in 2.0.4
thanx juliane

Geoff Howard wrote:

> There is good information about this at the wiki.  Go to 
> wiki.cocoondev.org and search for upload.
>
> Geoff
>
> upload-directory does not have to be under WEB-INF - it can be 
> relative or absolute anywhere on your system.  relative paths are 
> resolved from the servlet context - which is the main directory of 
> cocoon.
>
> Geoff
>
> At 08:20 AM 6/23/2003, you wrote:
>
>> hello alexander,
>> does your offer still exist? seems this is exactly what i have to do 
>> next and you could save me some time ;-)
>> thanx a lot!
>> juliane
>>
>> Alexander Schatten wrote:
>>
>>>
>>> well, I changed the parameter in the WEB-INF/web.xml:
>>>
>>>    <init-param>
>>>      <param-name>upload-directory</param-name>
>>>      <param-value>WEB-INF/work/upload-dir</param-value>
>>>    </init-param>
>>>
>>> and it works, but I am not sure, whether this directory has to be 
>>> below WEB-INF?
>>>
>>> however, one general remark: you must not forget, that this is a 
>>> general setting for *all* Cocoon applications. So what I do is, that 
>>> is set the directory as mentioned above, and in the cocoon 
>>> application I use an XSP file to move an uploaded file into the 
>>> projects destination directory, which seems to work pretty good and 
>>> is rather easy to implement.
>>>
>>> If you like, I could provide this XSP for you.
>>>
>>>
>>> Alex
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>>> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>
>



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


Re: File Uploads

Posted by Geoff Howard <co...@leverageweb.com>.
There is good information about this at the wiki.  Go to wiki.cocoondev.org 
and search for upload.

Geoff

upload-directory does not have to be under WEB-INF - it can be relative or 
absolute anywhere on your system.  relative paths are resolved from the 
servlet context - which is the main directory of cocoon.

Geoff

At 08:20 AM 6/23/2003, you wrote:
>hello alexander,
>does your offer still exist? seems this is exactly what i have to do next 
>and you could save me some time ;-)
>thanx a lot!
>juliane
>
>Alexander Schatten wrote:
>
>>
>>well, I changed the parameter in the WEB-INF/web.xml:
>>
>>    <init-param>
>>      <param-name>upload-directory</param-name>
>>      <param-value>WEB-INF/work/upload-dir</param-value>
>>    </init-param>
>>
>>and it works, but I am not sure, whether this directory has to be below 
>>WEB-INF?
>>
>>however, one general remark: you must not forget, that this is a general 
>>setting for *all* Cocoon applications. So what I do is, that is set the 
>>directory as mentioned above, and in the cocoon application I use an XSP 
>>file to move an uploaded file into the projects destination directory, 
>>which seems to work pretty good and is rather easy to implement.
>>
>>If you like, I could provide this XSP for you.
>>
>>
>>Alex
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>>For additional commands, e-mail: cocoon-users-help@xml.apache.org
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: cocoon-users-help@xml.apache.org
>
>


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


Re: File Uploads

Posted by juliane ndje <ju...@petra-productions.de>.
hello alexander,
does your offer still exist? seems this is exactly what i have to do 
next and you could save me some time ;-)
thanx a lot!
juliane

Alexander Schatten wrote:

>
> well, I changed the parameter in the WEB-INF/web.xml:
>
>    <init-param>
>      <param-name>upload-directory</param-name>
>      <param-value>WEB-INF/work/upload-dir</param-value>
>    </init-param>
>
> and it works, but I am not sure, whether this directory has to be 
> below WEB-INF?
>
> however, one general remark: you must not forget, that this is a 
> general setting for *all* Cocoon applications. So what I do is, that 
> is set the directory as mentioned above, and in the cocoon application 
> I use an XSP file to move an uploaded file into the projects 
> destination directory, which seems to work pretty good and is rather 
> easy to implement.
>
> If you like, I could provide this XSP for you.
>
>
> Alex
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>
>



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


RE: File Uploads

Posted by Geoff Howard <co...@leverageweb.com>.
I'd recommend doing this with an action.  The wiki covers this
pretty well (though it's clearer if you're using 2.0.x).

Check out:
http://wiki.cocoondev.org/Wiki.jsp?page=FileUploadsWithCocoon
http://wiki.cocoondev.org/Wiki.jsp?page=FileUploadWithAction

and http://wiki.cocoondev.org/Wiki.jsp?page=FileUploadsWithFlow
if you're using 2.1 (even if you don't use flow, this contains
useful info for the changes to the upload api in 2.1)

Geoff

> -----Original Message-----
> From: Alexander Schatten [mailto:alasan@gmx.at]
> Sent: Saturday, June 14, 2003 11:57 AM
> To: cocoon-users@xml.apache.org
> Subject: Re: File Uploads
>
>
> bosspring 2 wrote:
>
> > Hi!!
> >
> > I want upload files in a simple form, but I don´t know to modifie the
> > upload-directory because I write "pfc/uploads" in the file web.xml and
> > the form doesn't upload.
> >
> > What is the configuration of the parameters in web.xml? I want to use
> > pfc/uploads that upload-directory
>
> well, I changed the parameter in the WEB-INF/web.xml:
>
>     <init-param>
>       <param-name>upload-directory</param-name>
>       <param-value>WEB-INF/work/upload-dir</param-value>
>     </init-param>
>
> and it works, but I am not sure, whether this directory has to be below
> WEB-INF?
>
> however, one general remark: you must not forget, that this is a general
> setting for *all* Cocoon applications. So what I do is, that is set the
> directory as mentioned above, and in the cocoon application I use an XSP
> file to move an uploaded file into the projects destination directory,
> which seems to work pretty good and is rather easy to implement.
>
> If you like, I could provide this XSP for you.
>
>
> Alex
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>
>
>


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


Re: File Uploads

Posted by Alexander Schatten <al...@gmx.at>.
bosspring 2 wrote:

> Hi!!
>
> I want upload files in a simple form, but I don´t know to modifie the 
> upload-directory because I write "pfc/uploads" in the file web.xml and 
> the form doesn't upload.
>
> What is the configuration of the parameters in web.xml? I want to use 
> pfc/uploads that upload-directory

well, I changed the parameter in the WEB-INF/web.xml:

    <init-param>
      <param-name>upload-directory</param-name>
      <param-value>WEB-INF/work/upload-dir</param-value>
    </init-param>

and it works, but I am not sure, whether this directory has to be below 
WEB-INF?

however, one general remark: you must not forget, that this is a general 
setting for *all* Cocoon applications. So what I do is, that is set the 
directory as mentioned above, and in the cocoon application I use an XSP 
file to move an uploaded file into the projects destination directory, 
which seems to work pretty good and is rather easy to implement.

If you like, I could provide this XSP for you.


Alex


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


RE: File Uploads

Posted by Geoff Howard <co...@leverageweb.com>.
Which cocoon version?  This makes a lot of difference with
configuration.

Geoff

> -----Original Message-----
> From: bosspring 2 [mailto:bosspring2@hotmail.com]
> Sent: Saturday, June 14, 2003 10:30 AM
> To: cocoon-users@xml.apache.org
> Subject: File Uploads
>
>
> Hi!!
>
> I want upload files in a simple form, but I don´t know to modifie the
> upload-directory because I write "pfc/uploads" in the file
> web.xml and the
> form doesn't upload.
>
> What is the configuration of the parameters in web.xml? I want to use
> pfc/uploads that upload-directory
>
> Thank you.
>
> Miguel Ángel
>
> _________________________________________________________________
> Melodías, logos y mil servicios para tu teléfono en MSN Móviles.
> http://www.msn.es/MSNMovil/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>
>
>


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