[opencms-dev] Uploading a Files from RFS to VFS

Mario Jäger m.jaeger at alkacon.com
Thu Oct 7 09:23:51 CEST 2010



Hi,

To upload a file on a server, you need a form (where the user selects a file to upload with an<input ... type="file">  element) starting with this construct for example:

<form action="upload.jsp" enctype="multipart/form-data" method="post">

ACTION gives the information to which address/file the data shall be sent to. ENCTYPE determines how the form data is encoded, you have to use "multipart/form-data" here. METHOD specifies how the data shall be communicated.
If you use "POST" here for example, than the browser sends a special POST request with the data to the server.

When the user submits the form, then the jsp is called, which is set in ACTION and the file is sent of the browser to the server. The server saves the file in a temporary directory then. Then, the data have to be handled in
the called jsp.

But, you use no form here. And that is why, there is no MultiPartRequest and that is why, you get a NullpointerException.


You also can read files in the RFS with the OpenCms method org.opencms.util.CmsFileUtil.readFile() or with the Java own functionalities to read files. Then you get the content of a file in the RFS and you can handle that content
to create files in the VFS.

-- 
Kind Regards,
Mario.

-------------------
Mario Jäger

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org


Am 07.10.2010 06:54, schrieb Madhu Yadav:
> This is My code
>
> <%@ page import="org.opencms.workplace.explorer.*" %>
> <%@ page import="org.opencms.jsp.CmsJspActionElement" %>
> <%@ page import="javax.servlet.http.*" %>
>
>
> <%
> CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
> response);
> CmsNewResourceUpload upload = new CmsNewResourceUpload(cms);
> upload.setParamUploadFile ("c://img.jpg") ;
> System.out.println("UpLoad File"+ upload.getParamUploadFile());
> upload.setParamUploadFolder ("/sites/default/p1/");
> upload.setParamNewResourceName ("titi.jpg") ;
> upload.setParamUploadError ("Error while Uploading") ;
> upload.setParamUnzipFile ("false") ;
> String str=upload.getParamUploadFolder() ;
> System.out.println(str);
> upload.actionUpload () ;
> %>
>
>
>
> But i am getting a NullpointerException at
> upload.actionUpload();
>
> Please i Need help.............



More information about the opencms-dev mailing list