留言板

Does anyone have a file upload portlet?

Nhat Le,修改在12 年前。

Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
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!
thumbnail
Juhi Kumari,修改在12 年前。

RE: Does anyone have a file upload portlet?

Expert 帖子: 347 加入日期: 11-12-12 最近的帖子
Hi Nhat,
Put this line in your jsp
<label for=""><liferay-ui:message key="signature" /></label>
		<input type="file" name="<portlet:namespace />signature" id="<portlet:namespace />signature">

And add this line in your action class
UploadPortletRequest uploadRequest = PortalUtil
				.getUploadPortletRequest(actionRequest);
		String sourceFileName = uploadRequest.getFileName("signature");
		File file = uploadRequest.getFile("signature");
		if (Validator.isNotNull(sourceFileName) &amp;&amp; !file.exists()) {
			file.createNewFile();
		}
		 serviceContext = ServiceContextFactory
				.getInstance(DLFileEntry.class.getName(), actionRequest); 
		 long fId = 0l,stampId = 0l;
			List<dlfolder> dlFolders = DLFolderLocalServiceUtil.getDLFolders(
					0, DLFolderLocalServiceUtil.getDLFoldersCount());
for (DLFolder folder : dlFolders) {
				try {
					if (folder.getName().equalsIgnoreCase("Signature")) {
						fId = folder.getFolderId();
	}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
if (Validator.isNotNull(sourceFileName) ) {
			 DLFileEntryServiceUtil.addFileEntry(
					fId, sourceFileName, sourceFileName, "", "", file, serviceContext);
			}
</dlfolder>


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

Regards
Juhi
Nhat Le,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
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

&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;
&lt;%@ page language="java" contentType="text/html; charset=Windows-1256" pageEncoding="Windows-1256"%&gt;
<portlet:defineobjects />
    <script type="text/javascript">
        function send()
        {
            document.UploadForm.submit();
        }
    </script>
        <h3>Upload portlet:</h3>
        
        <form name="UploadForm" action="<portlet:actionURL/>" enctype="multipart/form-data" method="POST">
          <input type="file" name="fileName" size="50"><br>
          <input type="Submit" value="Upload File" onClick="send()">
        </form>


And here is my uploadPortlet.java


public class UploadPortlet extends GenericPortlet{

    protected String viewJSP;
    protected String process;
    protected Vector<!--?--> v=null;
    protected String realPath=null;

    public void init() throws PortletException {

        viewJSP = getInitParameter("view-jsp");
    }

    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
    {  

        realPath = getPortletContext().getRealPath("/");
        System.out.println(realPath);

        byte[] bytes = null;
        PortletContext portletContext = request.getPortletSession().getPortletContext();
        try{ 

            UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
            String sourceFileName =uploadRequest.getFileName("fileName");
            File file = uploadRequest.getFile("fileName");
            try {
                bytes = FileUtil.getBytes(file);
            } catch (IOException e2) {            
                e2.printStackTrace();
            }
            File newFile=null;

            if ((bytes != null) &amp;&amp; (bytes.length &gt; 0)) {

                try {

                    System.out.println(sourceFileName);

                    newFile = new File(realPath+"html/"+sourceFileName);
                    FileInputStream fileInputStream = new FileInputStream(file);
                    FileOutputStream fileOutputStream = new FileOutputStream(newFile);            
                    fileInputStream.read(bytes);        
                    
                    String value = new String(bytes);
                    System.out.println(value);
                    
                    fileOutputStream.write(bytes, 0, bytes.length);                    
                    fileOutputStream.close();
                    fileInputStream.close();
                } 
                catch (FileNotFoundException e) {
                    System.out.println("File Not Found.");                
                    e.printStackTrace();
                }
                catch (IOException e1){
                    System.out.println("Error Reading The File.");
                    e1.printStackTrace();
                }
            }

        } catch (Exception e) {
            System.out.println("Exception::::"+e.getMessage());
        }
    }
    public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException
    {

        doView(request,response);
    }

    public void doView(RenderRequest request, RenderResponse response)throws IOException 
    {
        String path=viewJSP;
        PortletRequestDispatcher portletRequestDispatcher = getPortletContext().getRequestDispatcher(path);
        if (portletRequestDispatcher == null) {
            _log.error(viewJSP + " is not a valid include");
        }
        else{

            try{
                portletRequestDispatcher.include(request, response);
            }
            catch(Exception e){                
                _log.error("Error Occured:"+e);
            }
        }


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?
thumbnail
Juhi Kumari,修改在12 年前。

RE: Does anyone have a file upload portlet?

Expert 帖子: 347 加入日期: 11-12-12 最近的帖子
Hi Nhat,
First tell me which version of liferay you are using?

Regards
Juhi
Nhat Le,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
Hi

I am using Liferay 6.0.5 with tomcat 6.0.26

Thanks!
thumbnail
Juhi Kumari,修改在12 年前。

RE: Does anyone have a file upload portlet?

Expert 帖子: 347 加入日期: 11-12-12 最近的帖子
Hi,
Please check your jsp once again. There is not proper actionURL in your code. Correct this one.

Regards
Juhi
thumbnail
Juhi Kumari,修改在12 年前。

RE: Does anyone have a file upload portlet?

Expert 帖子: 347 加入日期: 11-12-12 最近的帖子
Hi,
And in your java class extends MVCPortlet instead of GenericPortlet. MVCPortlet already extending GenericPortlet.

Regards
Juhi
Nhat Le,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
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,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
I am still a bit confused about this so if someone can help me that will be great!
Thanks
thumbnail
Mani kandan,修改在12 年前。

RE: Does anyone have a file upload portlet?

Expert 帖子: 492 加入日期: 10-9-15 最近的帖子
Try this thread, here
Nhat Le,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
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.
thumbnail
Mani kandan,修改在12 年前。

RE: Does anyone have a file upload portlet?

Expert 帖子: 492 加入日期: 10-9-15 最近的帖子
While seeing your code above, the files are storing in html directory not in Document Library
thumbnail
Jitendra Rajput,修改在12 年前。

RE: Does anyone have a file upload portlet?

Liferay Master 帖子: 875 加入日期: 11-1-7 最近的帖子
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,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
@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.
thumbnail
Jitendra Rajput,修改在12 年前。

RE: Does anyone have a file upload portlet?

Liferay Master 帖子: 875 加入日期: 11-1-7 最近的帖子
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.

DLFolder 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,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
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,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
Can someone help me with this please? emoticon
Nitu Saksena,修改在12 年前。

RE: Does anyone have a file upload portlet?

New Member 帖子: 11 加入日期: 11-2-2 最近的帖子
Hi Nhat,

Please try this code:



@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


import import org.springframework.web.bind.annotation.RequestMapping;


In your JSP you need to define you action URL


<portlet:actionurl name="uploadMultipleFile" var="uploadMultipleFileURL" />                                      

I have tested this code it works fine for me.

Hope this helps.
Nitu
Nhat Le,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
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,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
Can someone help me please?
Thanks.
Nhat Le,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
Can someone help me please? I am still stuck on this emoticon
thumbnail
Prakash Khanchandani,修改在12 年前。

RE: Does anyone have a file upload portlet?

Expert 帖子: 329 加入日期: 11-2-10 最近的帖子
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,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
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.
thumbnail
Prakash Khanchandani,修改在12 年前。

RE: Does anyone have a file upload portlet?

Expert 帖子: 329 加入日期: 11-2-10 最近的帖子
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.
Nhat Le,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
Thank you so much.
Just as confirmation, this is for liferay SDK 6.1 with liferay 6.1 right?
thumbnail
Prakash Khanchandani,修改在12 年前。

RE: Does anyone have a file upload portlet?

Expert 帖子: 329 加入日期: 11-2-10 最近的帖子
Yes for Liferay 6.1 and SDK 6.1.
Nhat Le,修改在12 年前。

RE: Does anyone have a file upload portlet?

Junior Member 帖子: 25 加入日期: 12-3-5 最近的帖子
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,修改在11 年前。

RE: Does anyone have a file upload portlet?

New Member 帖子: 22 加入日期: 09-3-12 最近的帖子
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,修改在11 年前。

RE: Does anyone have a file upload portlet?

New Member 帖子: 22 加入日期: 09-3-12 最近的帖子
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,修改在10 年前。

RE: Does anyone have a file upload portlet?

New Member 发布: 1 加入日期: 10-5-5 最近的帖子
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,修改在8 年前。

RE: Does anyone have a file upload portlet?

New Member 帖子: 15 加入日期: 15-8-5 最近的帖子
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??