[opencms-dev] How to use uploadfile function

Mohit Raj mohit.raj at amsoft.net
Tue Jan 4 12:58:27 CET 2005


Now I am working on version 5.0. Earlier it was 6.
Below is a code snippet which I have found at many places for uploading a
file to CMS VFS but cudnt make out which packages does it require.

<%

  com.opencms.file.CmsObject cmsObj  = new CmsObject();

  if   ( cmsObj.getRequestContext() != null )  //Returns Null
  {
    if ( cmsObj.getRequestContext().getRequest() != null ) // Throws error
if ANDed with above If
       {
            Enumeration e =
cmsObj.getRequestContext().getRequest().getFileNames();

          while (e.hasMoreElements()) {
	      	String  name = (String)e.nextElement();
        	      byte[] sourceByteArray =
cmsObj.getRequestContext().getRequest().getFile(name);
	            String  destFileName=
"/system/modules/com.amsoft.www/jsptemplates/"  + name;
                  out.println(destFileName); // This doesnt get printed
        	      File nomefile=new File(destFileName);
	            FileOutputStream outFileStream=new
java.io.FileOutputStream(nomefile);
        	      outFileStream.write(sourceByteArray);
	  }
	}
  }
%>

Currently am importing "com.opencms.file.*, java.util.*, com.opencms.core.*,
java.lang.* " . But cms.getRequestContext() always returns Null. And also
where can the source file path be specified in the above snippet.

Thanks,
Mohit


-----Original Message-----
From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org]On Behalf Of lists at rueth.info
Sent: Tuesday, January 04, 2005 12:26 PM
To: The OpenCms mailing list
Subject: Re: [opencms-dev] How to use uploadfile function



Which OpenCms version are you using? If version 6, then there is no more
com.opencms...., but rather org.opencms.... (and in some cases the
package structure also changes, e.g. from com.opencms.flex.jsp to
org.opencms.jsp. Best is to check out the source code and produce an
API from it or just search the source.

Regards
Ulrich

Mohit Raj <mohit.raj at amsoft.net> schrieb am 04.01.2005, 05:28:00:
> Hi,
>
> Ok, I have removed both the java packages from import. But then how to
> proceed for upload of content in opencms VFS. which packages do I need to
> import and does it requires any Servlets or command line support???
>
> Thanks
> Mohit
>
>
> Mohit Raj wrote:
>
> >
>
> Try to remove java.lang.Object.* First you don't need to import anything
> from java.lang, it is done implicitly and second - more important - what
> classes do you think does Object.* refer to? Object is a class and you
can't
> have any more dots after the classname or you don't have a class.
>
> chris
>
>
>
>
>
> _______________________________________________
> 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