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

Mario Jäger m.jaeger at alkacon.com
Fri Oct 8 09:31:09 CEST 2010



Hi,

before I try to solve your problem, I want to know, what the target is you want to reach. Do you want to upload local files in your OpenCms? I ask, because in your first code example you tried to upload the local file "c:\img.jpg".
In this case, you can use the "Upload" button in the OpenCms workplace. Or do you want to offer, that frontend users can select a file on the local hard drive, which will be uploaded to the OpenCms server? In this case, you can use
the Alkacon OAMP Webform Module, you can download here: http://www.alkacon.com/en/modules/downloads/alkacon_oamp_webform_1.3.1.html. How to install and how to use that module, you find in the root directory of the downloaded module
in "Alkacon_OAMP_Webform.pdf".

-- 
Kind Regards,
Mario.

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

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


Am 07.10.2010 12:18, schrieb Madhu Yadav:
> <html>
> <head>
> </head>
> <body>
> <form action="upload.jsp"  enctype="multipart/form-data" method="post">
> <input type="file" name="filename" />
> <input type="submit" value="ok" />
> </form>
> </body>
> </html>
>
> Upload jsp Page
>
> <%
> CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
> response);
> CmsNewResourceUpload upload = new CmsNewResourceUpload(cms);
> String str=request.getParameter("filename");
> upload.setParamUploadFile (str) ;
>
> System.out.println("UpLoadFile"+ upload.getParamUploadFile());//I am getting
> Null Here
>
> upload.setParamUploadFolder ("/sites/default/p1/");
> upload.setParamNewResourceName ("titi.jpg") ;
> upload.setParamUploadError ("Error while Uploading") ;
> upload.setParamUnzipFile ("false") ;
> String str1=upload.getParamUploadFolder() ;
> System.out.println(str1);
> upload.actionUpload () ;
> %>
>
> I am unable to Use request Object with "Post" action I f i use "get" i am
> getting null pointer Exception.
>
> Please Helpme as i am completely new to OpenCms
>
>
>
> Mario Jäger wrote:
>>
>>
>> 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.............
>> _______________________________________________
>> This mail is sent to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list, please visit
>> http://lists.opencms.org/mailman/listinfo/opencms-dev
>>
>>



More information about the opencms-dev mailing list