[opencms-dev] Uploading a file with other input types

Jesus Gabriel y Galan tech at einnovas.com
Thu Jun 24 12:51:01 CEST 2004


Hi all.

I am trying to upload a file through OpenCMS. I have a form with several
input types, for the example a text field and a file:

<form action="upload.jsp" method="post" ENCTYPE="multipart/form-data">
ID: <input type="text" name="id" value=""><br>
File: <INPUT TYPE=FILE NAME=file1><br>
<input type="submit">
</form>

I want to retreive the id parameter to use it as the file name. I have this
code:

com.opencms.flex.jsp.CmsJspActionElement cms = new
CmsJspActionElement(pageContext, request, response);
String id = request.getParameter("ID");
Enumeration files = cms.getRequestContext().getRequest().getFileNames();
while(files.hasMoreElements())
{
    String filename = (String) files.nextElement();
    byte[] filecontent =
cms.getRequestContext().getRequest().getFile(filename);
    FileOutputStream f = new FileOutputStream (new File ("/tmp/" + id +
".jpg"));
    f.write (filecontent);
    f.close();
}

The file gets written correctly, but the id parameter is null, so I get a
file called null.jpg. I've tried reading the id parameter with the
cms.getRequestContext().getRequest() object too, but the result was the
same.

Could anybody tell me if it's possible to do this and how?

Thanks in advance,

Jesus.





More information about the opencms-dev mailing list