Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Does anyone have a file upload portlet? Nhat Le 5. März 2012 01:08
RE: Does anyone have a file upload portlet? Juhi Kumari 5. März 2012 01:26
RE: Does anyone have a file upload portlet? Nhat Le 5. März 2012 01:36
RE: Does anyone have a file upload portlet? Juhi Kumari 5. März 2012 02:26
RE: Does anyone have a file upload portlet? Nhat Le 5. März 2012 03:27
RE: Does anyone have a file upload portlet? Juhi Kumari 5. März 2012 04:14
RE: Does anyone have a file upload portlet? Juhi Kumari 5. März 2012 04:17
RE: Does anyone have a file upload portlet? Nhat Le 5. März 2012 05:01
RE: Does anyone have a file upload portlet? Nhat Le 5. März 2012 19:34
RE: Does anyone have a file upload portlet? Manikandan S 5. März 2012 20:57
RE: Does anyone have a file upload portlet? Nhat Le 5. März 2012 21:05
RE: Does anyone have a file upload portlet? Manikandan S 5. März 2012 21:31
RE: Does anyone have a file upload portlet? Jitendra Rajput 5. März 2012 21:48
RE: Does anyone have a file upload portlet? Nhat Le 5. März 2012 21:56
RE: Does anyone have a file upload portlet? Jitendra Rajput 5. März 2012 22:08
RE: Does anyone have a file upload portlet? Nhat Le 5. März 2012 22:14
RE: Does anyone have a file upload portlet? Nhat Le 6. März 2012 14:02
RE: Does anyone have a file upload portlet? Nitu Saksena 6. März 2012 23:07
RE: Does anyone have a file upload portlet? Nhat Le 7. März 2012 00:41
RE: Does anyone have a file upload portlet? Nhat Le 7. März 2012 16:11
RE: Does anyone have a file upload portlet? Nhat Le 11. März 2012 18:26
RE: Does anyone have a file upload portlet? Prakash Khanchandani 12. März 2012 01:22
RE: Does anyone have a file upload portlet? Nhat Le 14. März 2012 00:29
RE: Does anyone have a file upload portlet? Prakash Khanchandani 14. März 2012 04:22
RE: Does anyone have a file upload portlet? Nhat Le 14. März 2012 18:56
RE: Does anyone have a file upload portlet? Prakash Khanchandani 14. März 2012 22:58
RE: Does anyone have a file upload portlet? Nhat Le 14. März 2012 23:43
RE: Does anyone have a file upload portlet? anil s kolhe 13. August 2012 05:59
RE: Does anyone have a file upload portlet? anil s kolhe 13. August 2012 21:35
RE: Does anyone have a file upload portlet? Anil Kumar NCH 4. Mai 2013 09:07
Nhat Le
Does anyone have a file upload portlet?
5. März 2012 01:08
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
5. März 2012 01:26
Antwort

Juhi Kumari

Rang: Expert

Nachrichten: 347

Eintrittsdatum: 12. Dezember 2011

Neue Beiträge

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?
5. März 2012 01:36
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
5. März 2012 02:26
Antwort

Juhi Kumari

Rang: Expert

Nachrichten: 347

Eintrittsdatum: 12. Dezember 2011

Neue Beiträge

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

Regards
Juhi
Nhat Le
RE: Does anyone have a file upload portlet?
5. März 2012 03:27
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

Hi

I am using Liferay 6.0.5 with tomcat 6.0.26

Thanks!
Juhi Kumari
RE: Does anyone have a file upload portlet?
5. März 2012 04:14
Antwort

Juhi Kumari

Rang: Expert

Nachrichten: 347

Eintrittsdatum: 12. Dezember 2011

Neue Beiträge

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?
5. März 2012 04:17
Antwort

Juhi Kumari

Rang: Expert

Nachrichten: 347

Eintrittsdatum: 12. Dezember 2011

Neue Beiträge

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?
5. März 2012 05:01
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
5. März 2012 19:34
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
5. März 2012 20:57
Antwort

Manikandan S

Rang: Expert

Nachrichten: 492

Eintrittsdatum: 15. September 2010

Neue Beiträge

Try this thread, here
Nhat Le
RE: Does anyone have a file upload portlet?
5. März 2012 21:05
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
5. März 2012 21:31
Antwort

Manikandan S

Rang: Expert

Nachrichten: 492

Eintrittsdatum: 15. September 2010

Neue Beiträge

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?
5. März 2012 21:48
Antwort

Jitendra Rajput

Rang: Liferay Master

Nachrichten: 748

Eintrittsdatum: 7. Januar 2011

Neue Beiträge

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?
5. März 2012 21:56
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

@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?
5. März 2012 22:08
Antwort

Jitendra Rajput

Rang: Liferay Master

Nachrichten: 748

Eintrittsdatum: 7. Januar 2011

Neue Beiträge

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?
5. März 2012 22:14
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
6. März 2012 14:02
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

Can someone help me with this please? emoticon
Nitu Saksena
RE: Does anyone have a file upload portlet?
6. März 2012 23:07
Antwort

Nitu Saksena

Rang: New Member

Nachrichten: 11

Eintrittsdatum: 1. Februar 2011

Neue Beiträge

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?
7. März 2012 00:41
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
7. März 2012 16:11
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

Can someone help me please?
Thanks.
Nhat Le
RE: Does anyone have a file upload portlet?
11. März 2012 18:26
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

Can someone help me please? I am still stuck on this emoticon
Prakash Khanchandani
RE: Does anyone have a file upload portlet?
12. März 2012 01:22
Antwort

Prakash Khanchandani

Rang: Expert

Nachrichten: 261

Eintrittsdatum: 10. Februar 2011

Neue Beiträge

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?
14. März 2012 00:29
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
14. März 2012 04:22
Antwort

Prakash Khanchandani

Rang: Expert

Nachrichten: 261

Eintrittsdatum: 10. Februar 2011

Neue Beiträge

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.
Anhänge: UploadDownloadFile.zip (191,6k)
Nhat Le
RE: Does anyone have a file upload portlet?
14. März 2012 18:56
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
14. März 2012 22:58
Antwort

Prakash Khanchandani

Rang: Expert

Nachrichten: 261

Eintrittsdatum: 10. Februar 2011

Neue Beiträge

Yes for Liferay 6.1 and SDK 6.1.
Nhat Le
RE: Does anyone have a file upload portlet?
14. März 2012 23:43
Antwort

Nhat Le

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 5. März 2012

Neue Beiträge

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?
13. August 2012 05:59
Antwort

anil s kolhe

Rang: New Member

Nachrichten: 22

Eintrittsdatum: 11. März 2009

Neue Beiträge

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?
13. August 2012 21:35
Antwort

anil s kolhe

Rang: New Member

Nachrichten: 22

Eintrittsdatum: 11. März 2009

Neue Beiträge

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?
4. Mai 2013 09:07
Antwort

Anil Kumar NCH

Rang: New Member

Nachrichten: 1

Eintrittsdatum: 4. Mai 2010

Neue Beiträge

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