Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Does anyone have a file upload portlet? Nhat Le March 5, 2012 1:08 AM
RE: Does anyone have a file upload portlet? Juhi Kumari March 5, 2012 1:26 AM
RE: Does anyone have a file upload portlet? Nhat Le March 5, 2012 1:36 AM
RE: Does anyone have a file upload portlet? Juhi Kumari March 5, 2012 2:26 AM
RE: Does anyone have a file upload portlet? Nhat Le March 5, 2012 3:27 AM
RE: Does anyone have a file upload portlet? Juhi Kumari March 5, 2012 4:14 AM
RE: Does anyone have a file upload portlet? Juhi Kumari March 5, 2012 4:17 AM
RE: Does anyone have a file upload portlet? Nhat Le March 5, 2012 5:01 AM
RE: Does anyone have a file upload portlet? Nhat Le March 5, 2012 7:34 PM
RE: Does anyone have a file upload portlet? Manikandan S March 5, 2012 8:57 PM
RE: Does anyone have a file upload portlet? Nhat Le March 5, 2012 9:05 PM
RE: Does anyone have a file upload portlet? Manikandan S March 5, 2012 9:31 PM
RE: Does anyone have a file upload portlet? Jitendra Rajput March 5, 2012 9:48 PM
RE: Does anyone have a file upload portlet? Nhat Le March 5, 2012 9:56 PM
RE: Does anyone have a file upload portlet? Jitendra Rajput March 5, 2012 10:08 PM
RE: Does anyone have a file upload portlet? Nhat Le March 5, 2012 10:14 PM
RE: Does anyone have a file upload portlet? Nhat Le March 6, 2012 2:02 PM
RE: Does anyone have a file upload portlet? Nitu Saksena March 6, 2012 11:07 PM
RE: Does anyone have a file upload portlet? Nhat Le March 7, 2012 12:41 AM
RE: Does anyone have a file upload portlet? Nhat Le March 7, 2012 4:11 PM
RE: Does anyone have a file upload portlet? Nhat Le March 11, 2012 6:26 PM
RE: Does anyone have a file upload portlet? Prakash Khanchandani March 12, 2012 1:22 AM
RE: Does anyone have a file upload portlet? Nhat Le March 14, 2012 12:29 AM
RE: Does anyone have a file upload portlet? Prakash Khanchandani March 14, 2012 4:22 AM
RE: Does anyone have a file upload portlet? Nhat Le March 14, 2012 6:56 PM
RE: Does anyone have a file upload portlet? Prakash Khanchandani March 14, 2012 10:58 PM
RE: Does anyone have a file upload portlet? Nhat Le March 14, 2012 11:43 PM
RE: Does anyone have a file upload portlet? anil s kolhe August 13, 2012 5:59 AM
RE: Does anyone have a file upload portlet? anil s kolhe August 13, 2012 9:35 PM
RE: Does anyone have a file upload portlet? Anil Kumar NCH May 4, 2013 9:07 AM
RE: Does anyone have a file upload portlet? Meera Prince September 6, 2015 10:53 PM
RE: Does anyone have a file upload portlet? Tran Du September 6, 2015 8:50 PM
Nhat Le
Does anyone have a file upload portlet?
March 5, 2012 1:08 AM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

I just need a simple file upload portlet, with the source so that it can upload files to the Document Library. I have tried numerous guides and I was unsuccessful in all of them. If possible, can I please have a SDK version of it so that I can modify it easier. All I need is for it to be able to upload a file, there is no need to display it afterwards or anything.
Thanks a lot!
Juhi Kumari
RE: Does anyone have a file upload portlet?
March 5, 2012 1:26 AM
Answer

Juhi Kumari

Rank: Expert

Posts: 347

Join Date: December 12, 2011

Recent Posts

Hi Nhat,
Put this line in your jsp
1<label for=""><liferay-ui:message key="signature" /></label>
2        <input type="file" name="<portlet:namespace />signature" id="<portlet:namespace />signature">

And add this line in your action class
 1UploadPortletRequest uploadRequest = PortalUtil
 2                .getUploadPortletRequest(actionRequest);
 3        String sourceFileName = uploadRequest.getFileName("signature");
 4        File file = uploadRequest.getFile("signature");
 5        if (Validator.isNotNull(sourceFileName) && !file.exists()) {
 6            file.createNewFile();
 7        }
 8         serviceContext = ServiceContextFactory
 9                .getInstance(DLFileEntry.class.getName(), actionRequest);
10         long fId = 0l,stampId = 0l;
11            List<DLFolder> dlFolders = DLFolderLocalServiceUtil.getDLFolders(
12                    0, DLFolderLocalServiceUtil.getDLFoldersCount());
13for (DLFolder folder : dlFolders) {
14                try {
15                    if (folder.getName().equalsIgnoreCase("Signature")) {
16                        fId = folder.getFolderId();
17    }
18                } catch (Exception e) {
19                    e.printStackTrace();
20                }
21            }
22if (Validator.isNotNull(sourceFileName) ) {
23             DLFileEntryServiceUtil.addFileEntry(
24                    fId, sourceFileName, sourceFileName, "", "", file, serviceContext);
25            }


The uploaded file will be store in Signature folder of Document Library Portlet.

Regards
Juhi
Nhat Le
RE: Does anyone have a file upload portlet?
March 5, 2012 1:36 AM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Hi Juhi,

Thanks for the quick reply but I was wondering which jsp should that be in? view.jsp?
And what is my action class emoticon?
Do you mind giving me the source code of the file, if possible?

Thanks a lot!
Nhat

Edit:

This is what I currently have in my view.jsp file
 1
 2<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 3<%@ page language="java" contentType="text/html; charset=Windows-1256" pageEncoding="Windows-1256"%>
 4<portlet:defineObjects />
 5    <script type="text/javascript">
 6        function send()
 7        {
 8            document.UploadForm.submit();
 9        }
10    </script>
11        <h3>Upload portlet:</h3>
12       
13        <form name="UploadForm" action="<portlet:actionURL/>" enctype="multipart/form-data" method="POST">
14          <input type="file" name="fileName" size="50"><br>
15          <input type="Submit" value="Upload File" onClick="send()">
16        </form>


And here is my uploadPortlet.java

 1
 2public class UploadPortlet extends GenericPortlet{
 3
 4    protected String viewJSP;
 5    protected String process;
 6    protected Vector<?> v=null;
 7    protected String realPath=null;
 8
 9    public void init() throws PortletException {
10
11        viewJSP = getInitParameter("view-jsp");
12    }
13
14    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
15    { 
16
17        realPath = getPortletContext().getRealPath("/");
18        System.out.println(realPath);
19
20        byte[] bytes = null;
21        PortletContext portletContext = request.getPortletSession().getPortletContext();
22        try{
23
24            UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
25            String sourceFileName =uploadRequest.getFileName("fileName");
26            File file = uploadRequest.getFile("fileName");
27            try {
28                bytes = FileUtil.getBytes(file);
29            } catch (IOException e2) {            
30                e2.printStackTrace();
31            }
32            File newFile=null;
33
34            if ((bytes != null) && (bytes.length > 0)) {
35
36                try {
37
38                    System.out.println(sourceFileName);
39
40                    newFile = new File(realPath+"html/"+sourceFileName);
41                    FileInputStream fileInputStream = new FileInputStream(file);
42                    FileOutputStream fileOutputStream = new FileOutputStream(newFile);            
43                    fileInputStream.read(bytes);       
44                   
45                    String value = new String(bytes);
46                    System.out.println(value);
47                   
48                    fileOutputStream.write(bytes, 0, bytes.length);                   
49                    fileOutputStream.close();
50                    fileInputStream.close();
51                }
52                catch (FileNotFoundException e) {
53                    System.out.println("File Not Found.");               
54                    e.printStackTrace();
55                }
56                catch (IOException e1){
57                    System.out.println("Error Reading The File.");
58                    e1.printStackTrace();
59                }
60            }
61
62        } catch (Exception e) {
63            System.out.println("Exception::::"+e.getMessage());
64        }
65    }
66    public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException
67    {
68
69        doView(request,response);
70    }
71
72    public void doView(RenderRequest request, RenderResponse response)throws IOException
73    {
74        String path=viewJSP;
75        PortletRequestDispatcher portletRequestDispatcher = getPortletContext().getRequestDispatcher(path);
76        if (portletRequestDispatcher == null) {
77            _log.error(viewJSP + " is not a valid include");
78        }
79        else{
80
81            try{
82                portletRequestDispatcher.include(request, response);
83            }
84            catch(Exception e){               
85                _log.error("Error Occured:"+e);
86            }
87        }


When I try to upload something, after I press submit, nothing happens and it just takes me back to the same page. Also, the file doesn't appear in the Documents Library for some reason. Can you see what is wrong with it?
Juhi Kumari
RE: Does anyone have a file upload portlet?
March 5, 2012 2:26 AM
Answer

Juhi Kumari

Rank: Expert

Posts: 347

Join Date: December 12, 2011

Recent Posts

Hi Nhat,
First tell me which version of liferay you are using?

Regards
Juhi
Nhat Le
RE: Does anyone have a file upload portlet?
March 5, 2012 3:27 AM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Hi

I am using Liferay 6.0.5 with tomcat 6.0.26

Thanks!
Juhi Kumari
RE: Does anyone have a file upload portlet?
March 5, 2012 4:14 AM
Answer

Juhi Kumari

Rank: Expert

Posts: 347

Join Date: December 12, 2011

Recent Posts

Hi,
Please check your jsp once again. There is not proper actionURL in your code. Correct this one.

Regards
Juhi
Juhi Kumari
RE: Does anyone have a file upload portlet?
March 5, 2012 4:17 AM
Answer

Juhi Kumari

Rank: Expert

Posts: 347

Join Date: December 12, 2011

Recent Posts

Hi,
And in your java class extends MVCPortlet instead of GenericPortlet. MVCPortlet already extending GenericPortlet.

Regards
Juhi
Nhat Le
RE: Does anyone have a file upload portlet?
March 5, 2012 5:01 AM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Hi,
Can you help me with what actionURL is? And what I should put in it? All I have in the portlet folder are those 2 files, that will be fine right?
My whole purpose of this is to just be able to upload a file that will appear in the Document Library so that admins can see them.
What do you mean extends it? What should I do to fix that?
Nhat Le
RE: Does anyone have a file upload portlet?
March 5, 2012 7:34 PM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

I am still a bit confused about this so if someone can help me that will be great!
Thanks
Manikandan S
RE: Does anyone have a file upload portlet?
March 5, 2012 8:57 PM
Answer

Manikandan S

Rank: Expert

Posts: 492

Join Date: September 15, 2010

Recent Posts

Try this thread, here
Nhat Le
RE: Does anyone have a file upload portlet?
March 5, 2012 9:05 PM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Yep I tried that thread already. I put both of the files into my fileupload-portlet folder. Then when i try to upload something, after I click on submit, it doesn't do anything. Nothing can be seen in the Document Library.
Manikandan S
RE: Does anyone have a file upload portlet?
March 5, 2012 9:31 PM
Answer

Manikandan S

Rank: Expert

Posts: 492

Join Date: September 15, 2010

Recent Posts

While seeing your code above, the files are storing in html directory not in Document Library
Jitendra Rajput
RE: Does anyone have a file upload portlet?
March 5, 2012 9:48 PM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

You can refer to below link for single/multiple file upload ..

http://jbrajput.blogspot.in/2011/12/multiple-file-upload-without-using-swf.html
Nhat Le
RE: Does anyone have a file upload portlet?
March 5, 2012 9:56 PM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

@Mani , do you know where I can find the html directory? And how can I make it save in the document Library?
@Jitendra: I tried that but I don't know where I should save the files, and the names of the files.
Jitendra Rajput
RE: Does anyone have a file upload portlet?
March 5, 2012 10:08 PM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

you should store what ever files uploaded by user into Document Library ..

Let me give you some idea ..

1) Create one folder inside document library (in same community/Org in which u have portlet) name its as "uploaded docs".

2) From your code when you want to store doc first of all get reference to folder we created in above step.

1DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0,"uploaded doc");


3) Once you have reference you to DL folder you can use DLFileEntryServiceUtil.addFileEntry() method to store doc .
Nhat Le
RE: Does anyone have a file upload portlet?
March 5, 2012 10:14 PM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Thanks for the reply, I will try that.
I was wondering where the different code breaks go, for example:
@ActionMapping(params = "myActions=uploadMultipleFile")
I was wondering where the string of code that contains that line goes. LIke, which file?
Do you have the completed portlet on your machine? If so, do you mind posting it here/emailing it to me? I can give you my email.

Thanks a lot.
Nhat Le
RE: Does anyone have a file upload portlet?
March 6, 2012 2:02 PM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Can someone help me with this please? emoticon
Nitu Saksena
RE: Does anyone have a file upload portlet?
March 6, 2012 11:07 PM
Answer

Nitu Saksena

Rank: New Member

Posts: 11

Join Date: February 1, 2011

Recent Posts

Hi Nhat,

Please try this code:

1
2
3@RequestMapping(params = "action=uploadMultipleFile")

This line goes just above the method you need to call on click from the Java class i.e probably your processAction method.

you will need to add this import
1
2
3import import org.springframework.web.bind.annotation.RequestMapping;

In your JSP you need to define you action URL
1
2
3<portlet:actionURL name="uploadMultipleFile" var="uploadMultipleFileURL"/>                                     
4<form action="<%= uploadMultipleFileURL.toString() %>" method="post" id="UploadForm" name="UploadForm" >

I have tested this code it works fine for me.

Hope this helps.
Nitu
Nhat Le
RE: Does anyone have a file upload portlet?
March 7, 2012 12:41 AM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Hi Nitu,

Thanks for the reply. Which code is this for? In this thread I have been talking about 2-3 different set of codes :\ Do you mean the non-Flash one?
And if possible, can someone send me a completed portlet that can upload stuff? I think I can learn better that way.

Thanks
Nhat Le
RE: Does anyone have a file upload portlet?
March 7, 2012 4:11 PM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Can someone help me please?
Thanks.
Nhat Le
RE: Does anyone have a file upload portlet?
March 11, 2012 6:26 PM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Can someone help me please? I am still stuck on this emoticon
Prakash Khanchandani
RE: Does anyone have a file upload portlet?
March 12, 2012 1:22 AM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 329

Join Date: February 10, 2011

Recent Posts

Somehow I am having problems attaching files to this post, so if you can give your email-id I can send you the sample portlet zipped.

Portlet was created with Liferay 6.1 plugins SDK.

The portlet uploads to the Documents and Media portlet. And also shows a list of files which were uploaded through our custom portlet.

Hope this will help.
Nhat Le
RE: Does anyone have a file upload portlet?
March 14, 2012 12:29 AM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Hi,

Sorry about the late reply. I have added you as a friend and I will post it on your wall. I prefer not to post it here, where it is public.

Thanks a lot.
Prakash Khanchandani
RE: Does anyone have a file upload portlet?
March 14, 2012 4:22 AM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 329

Join Date: February 10, 2011

Recent Posts

Sorry about the late reply. I have added you as a friend and I will post it on your wall. I prefer not to post it here, where it is public.


No need.

Here is the portlet.

Hope it helps.
Attachments: UploadDownloadFile.zip (191.6k)
Nhat Le
RE: Does anyone have a file upload portlet?
March 14, 2012 6:56 PM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Thank you so much.
Just as confirmation, this is for liferay SDK 6.1 with liferay 6.1 right?
Prakash Khanchandani
RE: Does anyone have a file upload portlet?
March 14, 2012 10:58 PM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 329

Join Date: February 10, 2011

Recent Posts

Yes for Liferay 6.1 and SDK 6.1.
Nhat Le
RE: Does anyone have a file upload portlet?
March 14, 2012 11:43 PM
Answer

Nhat Le

Rank: Junior Member

Posts: 25

Join Date: March 5, 2012

Recent Posts

Thank you very much. It is working very well now. i tried it with 6.0.5 and it didn't work but 6.1 works very well
anil s kolhe
RE: Does anyone have a file upload portlet?
August 13, 2012 5:59 AM
Answer

anil s kolhe

Rank: New Member

Posts: 22

Join Date: March 11, 2009

Recent Posts

I am getting following exception on LP 6.1.0
12:50:26,543 ERROR [BeanPropertiesImpl:337] jodd.bean.BeanException: Simple property not found: fileUpload Invalid property: 'UploadFileImpl#fil
eUpload' (actual:'UploadFileImpl#fileUpload', forced=false)
jodd.bean.BeanException: Simple property not found: fileUpload Invalid property: 'UploadFileImpl#fileUpload' (actual:'UploadFileImpl#fileUpload'
, forced=false)

Any idea why this exception is thrown.
anil s kolhe
RE: Does anyone have a file upload portlet?
August 13, 2012 9:35 PM
Answer

anil s kolhe

Rank: New Member

Posts: 22

Join Date: March 11, 2009

Recent Posts

Change keyProperty="fileUpload" to keyProperty="fileUploadId". KeyProperty should refer to primary key of model

<liferay-ui:search-container-row
className="com.fl.uploadfile.model.UploadFile"
keyProperty="fileUploadId" modelVar="fileUpload">
Anil Kumar NCH
RE: Does anyone have a file upload portlet?
May 4, 2013 9:07 AM
Answer

Anil Kumar NCH

Rank: New Member

Posts: 1

Join Date: May 4, 2010

Recent Posts

Hi,

Is upload portlet is working fine for you? I am struggling to build one. Could you please upload the complete .war file if possible?

Regards,
Anil
Tran Du
RE: Does anyone have a file upload portlet?
September 6, 2015 8:50 PM
Answer

Tran Du

Rank: New Member

Posts: 15

Join Date: August 4, 2015

Recent Posts

anil s kolhe:
I am getting following exception on LP 6.1.0
12:50:26,543 ERROR [BeanPropertiesImpl:337] jodd.bean.BeanException: Simple property not found: fileUpload Invalid property: 'UploadFileImpl#fil
eUpload' (actual:'UploadFileImpl#fileUpload', forced=false)
jodd.bean.BeanException: Simple property not found: fileUpload Invalid property: 'UploadFileImpl#fileUpload' (actual:'UploadFileImpl#fileUpload'
, forced=false)

Any idea why this exception is thrown.

I have the same problem when I try to do it from scratch, it works fine when I import Prakash's portlet. I do not show the result in the search container so no keyProperty here but I still get this jodd bean exception. Anyone has a suggestion??
Meera Prince
RE: Does anyone have a file upload portlet?
September 6, 2015 10:53 PM
Answer

Meera Prince

Rank: Liferay Legend

Posts: 1110

Join Date: February 8, 2011

Recent Posts