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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to