Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
ActionRequest and Form with enctype multipart/form-data Krzysztof Makowski June 16, 2010 12:48 AM
RE: ActionRequest and Form with enctype multipart/form-data Sandeep Nair June 16, 2010 1:17 AM
RE: ActionRequest and Form with enctype multipart/form-data Krzysztof Makowski June 16, 2010 1:20 AM
RE: ActionRequest and Form with enctype multipart/form-data Sandeep Nair June 16, 2010 1:35 AM
RE: ActionRequest and Form with enctype multipart/form-data Krzysztof Makowski June 16, 2010 1:37 AM
RE: ActionRequest and Form with enctype multipart/form-data Sandeep Nair June 16, 2010 1:39 AM
RE: ActionRequest and Form with enctype multipart/form-data Krzysztof Makowski June 16, 2010 1:43 AM
RE: ActionRequest and Form with enctype multipart/form-data Sandeep Nair June 16, 2010 1:49 AM
RE: ActionRequest and Form with enctype multipart/form-data Krzysztof Makowski June 16, 2010 1:52 AM
RE: ActionRequest and Form with enctype multipart/form-data Sandeep Nair June 16, 2010 1:55 AM
RE: ActionRequest and Form with enctype multipart/form-data Krzysztof Makowski June 16, 2010 2:02 AM
RE: ActionRequest and Form with enctype multipart/form-data Sandeep Nair June 16, 2010 2:18 AM
RE: ActionRequest and Form with enctype multipart/form-data Krzysztof Makowski June 16, 2010 2:21 AM
RE: ActionRequest and Form with enctype multipart/form-data Sandeep Nair June 16, 2010 2:28 AM
RE: ActionRequest and Form with enctype multipart/form-data Krzysztof Makowski June 16, 2010 3:18 AM
RE: ActionRequest and Form with enctype multipart/form-data Sandeep Nair June 16, 2010 3:25 AM
RE: ActionRequest and Form with enctype multipart/form-data Krzysztof Makowski June 16, 2010 3:28 AM
RE: ActionRequest and Form with enctype multipart/form-data MANOVINAYAK AYYAPPAN June 30, 2011 12:16 AM
RE: ActionRequest and Form with enctype multipart/form-data Amos Fong July 4, 2011 12:45 AM
RE: ActionRequest and Form with enctype multipart/form-data Jelmer Kuperus July 13, 2011 3:23 AM
RE: ActionRequest and Form with enctype multipart/form-data MANOVINAYAK AYYAPPAN August 4, 2011 3:43 AM
RE: ActionRequest and Form with enctype multipart/form-data Ketan Savaliya August 8, 2011 9:48 PM
RE: ActionRequest and Form with enctype multipart/form-data Laxman Rana May 15, 2012 1:33 AM
RE: ActionRequest and Form with enctype multipart/form-data Laura Liparulo July 12, 2012 4:28 PM
RE: ActionRequest and Form with enctype multipart/form-data anil s kolhe August 1, 2012 4:20 AM
RE: ActionRequest and Form with enctype multipart/form-data anil s kolhe August 3, 2012 3:42 AM
RE: ActionRequest and Form with enctype multipart/form-data Pankaj Bansal August 2, 2010 4:14 AM
RE: ActionRequest and Form with enctype multipart/form-data Fuad Efendi May 21, 2012 8:51 PM
RE: ActionRequest and Form with enctype multipart/form-data Laura Liparulo July 7, 2012 5:04 AM
RE: ActionRequest and Form with enctype multipart/form-data master slave June 2, 2013 10:28 AM
Krzysztof Makowski
ActionRequest and Form with enctype multipart/form-data
June 16, 2010 12:48 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

I am trying to create portlet in which I have form with some input text fields, input file, tags selection and permission selection.

Since I need to upload file in that form I need to use enctype="multipart/data-form" attribute in html form tag.

But after setting such enctype in processAction method I do not have access to data that is usually stored in ActionRequest object. Instead I have to use UploadPortletRequest.

For this I use:

1
2UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);


Thanks to UploadPortletRequest I can now get parameters that are usually stored in ActionRequest.

But unfortunatelly I also need to use code that depend on ActionRequest like

1
2
3ServiceContext serviceContext = ServiceContextFactory.getInstance(
4            JournalArticle.class.getName(), actionRequest);


Could you, dear community, suggest me how to nicely get not empty serviceContext object when using multipart/data-form enctype.

Or maybe it would be better to make actionRequest object filled with form data as in normal (not multipart/data-form form). I know that it is possible - I can see the example in liferay portal-impl source code. In class com.liferay.portlet.journal.action.EditArticleAction there are used both requests (ActionRequest and UploadPortletRequest) and both are not empty.
Sandeep Nair
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 1:17 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Hi,

I guess you can get UploadRequest from actionRequest.

Check out updateFileEntry method of EditFileEntryAction of Document library.

There liferay has used both uploadrequest and serviceContext.

Regards,
Sandeep
Krzysztof Makowski
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 1:20 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

Thanks, yes I know taht i can et UploadPortletRequest but ServiceContextFactory.getInstance(...) method expects actionRequest object not UploadPortletRequest.
Sandeep Nair
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 1:35 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Yes but you already have actionRequest in your processAction. Heres the full snippet in which they have used both serviceContext and UploadRequest together

 1        [b]UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
 2            actionRequest);[/b]
 3
 4        String cmd = ParamUtil.getString(uploadRequest, Constants.CMD);
 5
 6        ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
 7            WebKeys.THEME_DISPLAY);
 8
 9        long folderId = ParamUtil.getLong(uploadRequest, "folderId");
10        long newFolderId = ParamUtil.getLong(uploadRequest, "newFolderId");
11        String name = ParamUtil.getString(uploadRequest, "name");
12        String sourceFileName = uploadRequest.getFileName("file");
13
14        String title = ParamUtil.getString(uploadRequest, "title");
15        String description = ParamUtil.getString(uploadRequest, "description");
16
17        String extraSettings = PropertiesUtil.toString(
18            fileEntryForm.getExtraSettingsProperties());
19
20        File file = uploadRequest.getFile("file");
21
22        [b]ServiceContext serviceContext = ServiceContextFactory.getInstance(
23            DLFileEntry.class.getName(), actionRequest);
24[/b]
25        if (cmd.equals(Constants.ADD)) {
26
27            // Add file entry
28
29            DLFolderPermission.check(
30                themeDisplay.getPermissionChecker(), folderId,
31                ActionKeys.ADD_DOCUMENT);
32
33            [b]DLFileEntry entry = DLFileEntryLocalServiceUtil.addFileEntry(
34                themeDisplay.getUserId(), folderId, sourceFileName, title,
35                description, extraSettings, file, serviceContext);[/b]


Regards,
Sandeep
Krzysztof Makowski
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 1:37 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

Right but I develop my portlet as plugin without struts. So I my ActionRequest object is empty
Sandeep Nair
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 1:39 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Can you just paste the entire method snippet with method signature?

Regards,
Sandeep
Krzysztof Makowski
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 1:43 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

 1
 2
 3    public void processAction(ActionRequest actionRequest,
 4            ActionResponse actionResponse) throws IOException, PortletException {
 5
 6        String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
 7        System.out.println(cmd); //returns empty string
 8
 9        UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
10            actionRequest);
11
12        cmd = ParamUtil.getString(uploadRequest, Constants.CMD);
13
14        System.out.println(cmd); //returns expected value
15
16        ServiceContext serviceContext = ServiceContextFactory.getInstance(
17            JournalArticle.class.getName(), actionRequest);
18
19        //since actionRequest is empty serviceContext will be also empty which I would like to avoid
20        }
Sandeep Nair
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 1:49 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Hi,

That method is perfectly fine friend. You wont have any problem using that. If you see getInstance method of ServiceContextFactory in source, you will see that,what you have written is sufficient. Do you get any error using that?

Regards,
Sandeep
Krzysztof Makowski
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 1:52 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

No I not get eny error but I need serviceContext object not to be empty. At the moment IT IS empty.
Sandeep Nair
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 1:55 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

It will not be empty. To check try doing this

ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
WebKeys.THEME_DISPLAY);

System.out.println("CompanyId :"+ themeDisplay.getCompanyId());
System.out.println("Layout URL :"+ PortalUtil.getLayoutURL(themeDisplay));
System.out.println("PortalURL:"+ PortalUtil.getPortalURL(actionRequest));

These are teh values that are used internally in ServiceContextFactory to get serviceContext

Regards,
Sandeep
Krzysztof Makowski
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 2:02 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

Ok I agree that themeDisplay object is still inside serviceContext object but if I execute such method as serviceContext.getTagsCategories() I receive empty array of strings.
Sandeep Nair
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 2:18 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

If you dont use uploadrequest and are using only actionrequest with parameters populated in actionrequest, do u get tagCategories from serviceContext? If you dont get there, you wont get it here too.

Regards,
Sandeep
Krzysztof Makowski
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 2:21 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

If you dont use uploadrequest and are using only actionrequest with parameters populated in actionrequest, do u get tagCategories from serviceContext?


Yes. If I use only actionRequest without setting multipart/form-data, I successfully receive populated serviceContext.
Sandeep Nair
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 2:28 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Are you able to get tagsCategories using this?

ParamUtil.getString(uploadRequest, "tagsCategories"));

Regards,
Sandeep
Krzysztof Makowski
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 3:18 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

Yes
Sandeep Nair
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 3:25 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

So the problem is all the request parameters are not available in serviceContext if we use that.

So identify which are teh request parameters that are set in serviceContext inside the method, and manually set those after you have retrieved serviceContext from factory from uploadRequest.

Regards,
Sandeep
Krzysztof Makowski
RE: ActionRequest and Form with enctype multipart/form-data
June 16, 2010 3:28 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

Yes of course. Thanks but I knew that I can add it manually. But my question from first post in this thread was how to do it like it is done in EditArticleAction class. In that class both actionrequest and uploadPortletRequest are not empty
Pankaj Bansal
RE: ActionRequest and Form with enctype multipart/form-data
August 2, 2010 4:14 AM
Answer

Pankaj Bansal

Rank: New Member

Posts: 4

Join Date: July 28, 2010

Recent Posts

I am facing the same problem. Sandeep can you please look in to it i am pasting my code here.
SAVEATTACHMENT(){
public ArrayList saveAttachments(ActionRequest request){
ResourceBundle rb=ResourceBundle.getBundle("com.test.messages",request.getLocale());
String fileName="";
boolean isMultipart=PortletFileUpload.isMultipartContent(request);
ArrayList savedFileList=new ArrayList();
if(isMultipart){
FileItemFactory factory=new DiskFileItemFactory();
PortletFileUpload upload=new PortletFileUpload(factory);
List items=null;
try{
items=upload.parseRequest(request);
}catch(FileUploadException e){
e.printStackTrace();
}
Iterator itr=items.iterator();
while(itr.hasNext()){
FileItem item=(FileItem)itr.next();
if(!item.isFormField()){
try{
String itemName=item.getName();

try{
fileName=itemName.substring(itemName.lastIndexOf("\\"),itemName.length());

}catch(Exception e){continue;}
File savedFile=new File(rb.getString("tomcat.attachment.filepath")+fileName);

item.write(savedFile);

savedFileList.add(fileName);
}catch(Exception e){e.printStackTrace();savedFileList.add(fileName+" Not Attached");continue;}
}
}
}
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
request.setAttribute("targetSection", ParamUtil.getString(uploadRequest, "targetSection")==null?"": ParamUtil.getString(uploadRequest, "targetSection"));
request.setAttribute("subject",ParamUtil.getString(uploadRequest,"subject")==null?""emoticonaramUtil.getString(uploadRequest,"subject"));
request.setAttribute("mailbody",ParamUtil.getString(uploadRequest,"mailbody")==null?""emoticonaramUtil.getString(uploadRequest,"mailbody"));


return savedFileList;
}


Above function is saving file on server and code in bold letters is getting the form data in string datatype that i am not getting..bcoz i use multipart enctype. if i put this bold code above to ####if(isMultipart){##### then it will return the data but then i am not able to load the file on server.
MANOVINAYAK AYYAPPAN
RE: ActionRequest and Form with enctype multipart/form-data
June 30, 2011 12:16 AM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

Recent Posts

Hi Krzysztof Makowski,

Sorry for putting this so late, I am newbie in liferay.

I would like to know, whether you found a solution for this problem.

I am stuck with this problem big time now. I am working on portlet that involves upload of Document library file.

I am unable to retrieve the assetCategories from the JSP page using the Service Context.

serviceContext.getAssetCategoryIds() returns NULL.

Please share your solution, if you have one.

Regards,
Mano
Amos Fong
RE: ActionRequest and Form with enctype multipart/form-data
July 4, 2011 12:45 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1844

Join Date: October 7, 2008

Recent Posts

Hi Manovinayak,

What I've done is this, which is not as nice but it should work.
1
2        ServiceContext serviceContext = ServiceContextFactory.getInstance(
3            uploadRequest);
4
5        long[] assetCategoryIds = StringUtil.split(
6            (String)serviceContext.getAttribute("assetCategoryIds"), 0L);
Jelmer Kuperus
RE: ActionRequest and Form with enctype multipart/form-data
July 13, 2011 3:23 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

I ran into the same problem some time back. I wrote a servlet filter to work around it. See the attached files

It works but it's a pain if you do not also apply this patch

http://issues.liferay.com/browse/LPS-17037
Attachments: multipart-filter.zip (4.4k)
MANOVINAYAK AYYAPPAN
RE: ActionRequest and Form with enctype multipart/form-data
August 4, 2011 3:43 AM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

Recent Posts

Hi All,

Sorry for putting this so late.

I found the solution for this long backemoticon, but I forgot to come in here and post it.

Here it is

Add this init-param in portlet.xml

copy-request-parameters and set it to true.

You will have all your input fields along with your file in your uploadRequest .

This worked for meemoticon.

Regards,
Mano
Ketan Savaliya
RE: ActionRequest and Form with enctype multipart/form-data
August 8, 2011 9:48 PM
Answer

Ketan Savaliya

Rank: Junior Member

Posts: 76

Join Date: March 3, 2011

Recent Posts

MANOVINAYAK AYYAPPAN:
Hi All,

Sorry for putting this so late.

I found the solution for this long backemoticon, but I forgot to come in here and post it.

Here it is

Add this init-param in portlet.xml

copy-request-parameters and set it to true.

You will have all your input fields along with your file in your uploadRequest .

This worked for meemoticon.
/quote]

Hi, Manovinayak

i have same problem with working string and file data within same form. which param set in portlet.xml i did't got u please give detail solution. event i dont understand what is copy-request-parameters.

Thanks,
Ketan
Laxman Rana
RE: ActionRequest and Form with enctype multipart/form-data
May 15, 2012 1:33 AM
Answer

Laxman Rana

Rank: Junior Member

Posts: 42

Join Date: February 29, 2012

Recent Posts

i have done action request wirh multipart/form-data..
my code is...
jsp file
 1<aui:form action="<%= uploadRFPUrl %>" method="POST" name="form" enctype="multipart/form-data" >
 2<aui:fieldset>
 3<aui:input name="name" id="rfp" onChange="Check();"></aui:input>            
 4<input type="file" name="docPath"/>
 5</aui:fieldset>
 6<aui:button-row>
 7<aui:button value="Submit" type="submit"></aui:button>
 8<aui:button type="reset"  value="Reset"/>
 9</aui:button-row>
10</aui:form> 


Controller

 1public void uploadRFP(ActionRequest request, ActionResponse response)
 2    throws Exception {
 3    ClassName obj = fromRequset(request);
 4}
 5
 6private ClassName fromRequset(PortletRequest req) {
 7       
 8       
 9       
10        UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(req);
11       
12       
13        ClassImpl obj = new ClassImpl();
14       
15        obj.setname(ParamUtil.getLong(uploadRequest, "name"));
16        srcFile=uploadRequest.getFileName("rfpdocPath");
17        file=uploadRequest.getFile("rfpdocPath");
18       
19        return obj;
20    }
Fuad Efendi
RE: ActionRequest and Form with enctype multipart/form-data
May 21, 2012 8:51 PM
Answer

Fuad Efendi

Rank: Regular Member

Posts: 148

Join Date: April 5, 2007

Recent Posts

Krzysztof Makowski:
I am trying to create portlet in which I have form with some input text fields, input file, tags selection and permission selection.

Since I need to upload file in that form I need to use enctype="multipart/data-form" attribute in html form tag.

But after setting such enctype in processAction method I do not have access to data that is usually stored in ActionRequest object. Instead I have to use UploadPortletRequest.

For this I use:

1
2UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);


Thanks to UploadPortletRequest I can now get parameters that are usually stored in ActionRequest.

But unfortunatelly I also need to use code that depend on ActionRequest like

1
2
3ServiceContext serviceContext = ServiceContextFactory.getInstance(
4            JournalArticle.class.getName(), actionRequest);


Could you, dear community, suggest me how to nicely get not empty serviceContext object when using multipart/data-form enctype.

Or maybe it would be better to make actionRequest object filled with form data as in normal (not multipart/data-form form). I know that it is possible - I can see the example in liferay portal-impl source code. In class com.liferay.portlet.journal.action.EditArticleAction there are used both requests (ActionRequest and UploadPortletRequest) and both are not empty.



Liferay 6.1 CE, the problem still exists; weird...

BTW, why I can't call PortalUtil.getUploadPortletRequest(actionRequest); two times?!! I lose some parameters...


Simple test scenario, and it does not work, test != test2:

1        UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
2        String test = ParamUtil.getString(uploadRequest, "test");
3        LOG.debug("test=" + test);
4        String test2 = ParamUtil.getString(actionRequest, "test");
5        LOG.debug("test2=" + test2);
Laura Liparulo
RE: ActionRequest and Form with enctype multipart/form-data
July 7, 2012 5:04 AM
Answer

Laura Liparulo

Rank: Junior Member

Posts: 38

Join Date: June 30, 2012

Recent Posts

Hi guys I'm posting you my Portlet method and edit.jsp.. it works fine :-) I've also included the upload progress bar :-) emoticonemoticon
emoticon
 1
 2[b]<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
 3<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
 4<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
 5<%@ page import="com.liferay.portal.kernel.util.ParamUtil"%>
 6<%@ page import="com.liferay.portal.kernel.util.Validator"%>
 7<%@ page import="javax.portlet.PortletPreferences"%>
 8<%@ page import="com.liferay.util.PwdGenerator"%>
 9<portlet:defineObjects />
10<%
11String uploadProgressId = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
12    PortletPreferences prefs = renderRequest.getPreferences();
13
14%>
15
16   
17
18<portlet:actionURL var="editCaseURL" name="uploadCase">
19    <portlet:param name="jspPage" value="/edit.jsp" />
20</portlet:actionURL>
21<liferay-ui:success key="success" message=" YEAH. Case uploaded successfully!" />
22<liferay-ui:error key="error"
23    message="Sorry, an error prevented the upload. Please try again." />
24    <liferay-ui:upload-progress
25    id="<%= uploadProgressId %>"
26    message="uploading"
27    redirect="<%= editCaseURL %>"
28  />
29
30<aui:form action="<%= editCaseURL %>" enctype="multipart/form-data" method="post" >
31<aui:input type="file" name="fileName" size="75"/>
32<input type="submit" value="<liferay-ui:message key="upload" />" onClick="<%= uploadProgressId %>.startProgress(); return true;"/>
33<!--  aui:button type="submit" value="Save" /-->
34</aui:form>
35
36
37<br />
38<br />
39<br />
40<br />
41<portlet:renderURL var="viewCaseURL">
42    <portlet:param name="jspPage" value="/view2.jsp" />
43</portlet:renderURL>
44
45<aui:button onClick="<%=viewCaseURL%>" value="view Uploaded Case" />[/b]

this is the UPLOAD method:

 1[b]    public void uploadCase(ActionRequest actionRequest,
 2            ActionResponse actionRresponse) throws PortletException,
 3            IOException {
 4
 5        String folder = getInitParameter("uploadFolder");
 6        realPath = getPortletContext().getRealPath("/");
 7
 8        logger.info("RealPath" + realPath + " UploadFolder :" + folder);
 9        try {
10            logger.info("Siamo nel try");
11            UploadPortletRequest uploadRequest = PortalUtil
12                    .getUploadPortletRequest(actionRequest);
13            String sourceFileName = uploadRequest.getFileName("fileName");
14            File file = uploadRequest.getFile("fileName");
15
16            logger.info("Nome file:" + uploadRequest.getFileName("fileName"));
17            // logger.info("Nome file file:" + file.getName());
18            File newFile = null;
19            newFile = new File(folder + sourceFileName);
20            logger.info("New file name: " + newFile.getName());
21            logger.info("New file path: " + newFile.getPath());
22
23            try {
24                InputStream in = uploadRequest.getFileAsStream("fileName");
25                FileInputStream fis = new FileInputStream(file);
26                FileOutputStream fos = new FileOutputStream(newFile);
27
28                byte[] bytes_ = FileUtil.getBytes(in);
29                int i = fis.read(bytes_);
30
31                while (i != -1) {
32                    fos.write(bytes_, 0, i);
33                    i = fis.read(bytes_);
34                }
35                fis.close();
36                fos.close();
37                Float size = (float) newFile.length();
38                System.out.println("file size bytes:" + size);
39                System.out.println("file size Mb:" + size / 1048576);
40
41                logger.info("File created: " + newFile.getName());
42
43                  
44                  } catch (FileNotFoundException e) {
45                  System.out.println("File Not Found."); e.printStackTrace();
46                 } catch (IOException e1) {
47                System.out.println("Error Reading The File.");
48                e1.printStackTrace();
49            }
50        } catch (Exception e) {
51            System.out.println("Error Reading The File.");
52            e.printStackTrace();
53        }
54
55    }
56
57}
58[/b]
Laura Liparulo
RE: ActionRequest and Form with enctype multipart/form-data
July 12, 2012 4:28 PM
Answer

Laura Liparulo

Rank: Junior Member

Posts: 38

Join Date: June 30, 2012

Recent Posts

You can see my post:
https://www.liferay.com/community/forums/-/message_boards/message/14831354
I've posted full working code with multipart/form-data (file + text input)...
anil s kolhe
RE: ActionRequest and Form with enctype multipart/form-data
August 1, 2012 4:20 AM
Answer

anil s kolhe

Rank: New Member

Posts: 22

Join Date: March 11, 2009

Recent Posts

Hi Laura,
Not able to find the files.
Please post the code or zip here.

Thanks
Anil
anil s kolhe
RE: ActionRequest and Form with enctype multipart/form-data
August 3, 2012 3:42 AM
Answer

anil s kolhe

Rank: New Member

Posts: 22

Join Date: March 11, 2009

Recent Posts

Hi,
I got similar upload file portlet at
http://www.liferay.com/community/forums/-/message_boards/message/12826911

Thanks
Anil
master slave
RE: ActionRequest and Form with enctype multipart/form-data
June 2, 2013 10:28 AM
Answer

master slave

Rank: Junior Member

Posts: 31

Join Date: April 8, 2013

Recent Posts

To solve this , instead of this :
1
2        String param=ParamUtil.getString(request,"param");


Do this :
1
2        UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
3
4        String param=ParamUtil.getString(uploadPortletRequest,"param");