R: [opencms-dev] upload a file

Andrea Frittoli lorblond at inwind.it
Wed May 28 17:13:02 CEST 2003


thanx Stephan,
your help was very useful!!

andrea

> you can not make any changes to the online project.
> You have to login and switch to an offline project. There may be an 
> tempfileProject with id 3 (dont know if this is alway so) 
> that you can use. Otherwise you can create one with your 
> CmsObject. The CmsRequestContext has a method 
> setCurrentProject(int id) to switch the 
> project.
> There you can create your resource and publish it directly. 
> Afterwards switch back to the old project.
> 
> IMPORTANT NOTE: When you login as admin your 
> CmsRequestContext will be 
> generated newly (new instance). So you have to do your 
> parameter processing 
> and so on before.
> 
> Bye,
> Stephan
> 
> Am Dienstag, 27. Mai 2003 16:18 schrieben Sie:
> > hi,
> >
> > I'm trying to upload a files from a JSP page in the OpenCMS 
> VFS. When 
> > I'm logged in the workplace as admin, if I lock the "uploads" 
> > directory, everything works fine. If I publish the project, 
> and logout 
> > from the workplace, I get an exception, it seems guest doesn't have 
> > the rights to write in the "uploads" directory (but I granted 
> > read/write access to guests)
> >
> > I tried also something like
> >
> >   cms.loginUser("admin",password)
> >   cms.lockResource(WORKING_PATH);
> >
> > but I get an "Access Denied" exception!
> >
> > This is the JSP code:
> >
> > <form method="post" enctype="multipart/form-data" action="#">
> >       <b>Select a file and submit!</b>
> >       <input type="file" name="uploader"/>
> >       <br/>
> >       <input type="submit" value="upload!"/>
> > </form>
> > <%String WORKING_PATH="/andrea/uploads/";
> >   com.opencms.file.CmsObject cms = 
> > ((com.opencms.flex.cache.CmsFlexRequest)request).getCmsObject();
> >   com.opencms.file.CmsRequestContext reqContext = 
> > cms.getRequestContext();
> >   com.opencms.core.CmsRequestHttpServlet req = 
> > (com.opencms.core.CmsRequestHttpServlet)(reqContext.getRequest());
> >   java.util.Enumeration files = req.getFileNames();
> >   while(files.hasMoreElements()){
> >     String this_filename = (String) files.nextElement();
> >     byte[] filecontent = req.getFile(this_filename);
> >     cms.createResource(WORKING_PATH, this_filename, "binary", null, 
> > filecontent);
> >   }%>
> >
> > what's wrong in this JSP? please help!
> > TIA
> >
> > Andrea Frittoli
> >
> >
> > _______________________________________________
> > This mail is send to you from the opencms-dev mailing list
> > To change your list options, or to unsubscribe from the 
> list, please 
> > visit http://mail.opencms.org/mailman/listinfo/opencms-dev
> 
> -- 
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, 
> please visit http://mail.opencms.org/mailman/listinfo/opencms-dev
> 





More information about the opencms-dev mailing list