[opencms-dev] create a new resource uploading a file

Marco Tizzano marcotizzano at inwind.it
Tue Nov 4 18:06:00 CET 2003


I'm trying to create a new resouce uploding a file. 
 
But it doesn't work.
 
I've used the code found in the mailing-list archives:
 
<%
CmsObject cms = ((CmsFlexRequest)request).getCmsObject();
 
CmsRequestContext reqContext = cms.getRequestContext();
 
out.println(reqContext.currentProject().getId() + " " +
reqContext.currentProject().getName());
   
String localfile = request.getParameter("myfile");
String filename =
localfile.substring(localfile.lastIndexOf("\\"),localfile.length());
String type =
filename.substring(filename.lastIndexOf("."),filename.length());
 
 
String WORKING_PATH="/mysite/test";
cms.loginUser("Admin","admin");
 
reqContext.setCurrentProject(3);
 
cms.lockResource(WORKING_PATH); //this one doesn't work. I have to
comment it
 
CmsRequestHttpServlet req =
(CmsRequestHttpServlet)(reqContext.getRequest());
java.util.Enumeration files = req.getFileNames();
while(files.hasMoreElements()){
     String this_filename = (String) files.nextElement();
     byte[] filecontent = req.getFile(this_filename);
     out.println(this_filename);
     cms.createResource(WORKING_PATH, this_filename, "binary", null,
            filecontent);
}
%>
 
Unfortunely, the only exception i can catch is the JasperException and i
cannot understand what is happen.
 
Someone can help me? Urgent, please.
 
 
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20031104/57856a34/attachment.htm>


More information about the opencms-dev mailing list