Sandeep Nair
Sandeep Nair

Reputation: 3650

Multiple file upload in Liferay 6.1

Has anyone tried multiple file upload in Liferay 6.1. I was trying to do it the same way as it was in 6.0 and its failing badly. I see begin link on top left of the page and not withing portlet. When i click that and select some files, the control doesnt go to my portlet. I have checked my portlet.xml and verified the portlet-class is proper. Here's the snippet in jsp

<liferay-portlet:actionURL doAsUserId="<%= user.getUserId() %>" windowState="pop_up" name="uploadFile" var="uploadFileURL" >
    <portlet:param name="jspPage" value="/html/fileuploadportlet/view.jsp" />
</liferay-portlet:actionURL>


<div class="lfr-dynamic-uploader">
        <div class="lfr-upload-container" id="<portlet:namespace />fileUpload"></div>
    </div>
<div id="<portlet:namespace/>fallback"></div>
<aui:script use="liferay-upload">
    new Liferay.Upload({
        allowedFileTypes: '<%= StringUtil.merge(PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA)) %>',
        container: '#<portlet:namespace />fileUpload',
        maxFileSize: <%=Long.parseLong(PrefsPropsUtil.getString(PropsKeys.DL_FILE_MAX_SIZE)) %> / 1024,
        namespace:'<%=renderResponse.getNamespace()%>',
        uploadFile: '<%=uploadFileURL.toString()%>',
        buttonHeight: 100,
        buttonText: 'BEGIN',
        buttonWidth: 100,
        onFileComplete: function(){alert('fileComplete');},
        onUploadError: function(){alert('error');}
    });
</aui:script>

And here's the processAction method of my portlet

@Override
    public void processAction(ActionRequest actionRequest,
            ActionResponse actionResponse) throws IOException, PortletException {
        System.out.println("Something");
        UploadPortletRequest uploadRequest=PortalUtil.getUploadPortletRequest(actionRequest);
        File file =uploadRequest.getFile("file");
        System.out.println(file.getName());
        for(int i=0;i<50000;i++){
            System.out.println("Something");
        }

    }

Screenshot

Upvotes: 3

Views: 5668

Answers (1)

Prakash K
Prakash K

Reputation: 11698

Can you check if your <aui:script> is correct, below is what is shown in html/portlet/document_library/upload_multiple_file_entries.jsp, I think you are missing the attribute tempFileURL:

    <aui:script use="liferay-upload">
        new Liferay.Upload(
            {
                allowedFileTypes: '<%= allowedFileExtensions %>',
                container: '#<portlet:namespace />fileUpload',
                deleteFile: '<liferay-portlet:actionURL doAsUserId="<%= user.getUserId() %>"><portlet:param name="struts_action" value="/document_library/edit_file_entry" /><portlet:param name="<%= Constants.CMD %>" value="<%= Constants.DELETE_TEMP %>" /><portlet:param name="folderId" value="<%= String.valueOf(folderId) %>" /></liferay-portlet:actionURL>&ticketKey=<%= ticket.getKey() %><liferay-ui:input-permissions-params modelName="<%= DLFileEntryConstants.getClassName() %>" />',
                fileDescription: '<%= StringUtil.merge(PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA)) %>',
                maxFileSize: '<%= PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE) %> B',
                metadataContainer: '#<portlet:namespace />commonFileMetadataContainer',
                metadataExplanationContainer: '#<portlet:namespace />metadataExplanationContainer',
                namespace: '<portlet:namespace />',
                tempFileURL: {
                    method: Liferay.Service.DL.DLApp.getTempFileEntryNames,
                    params: {
                        groupId: <%= scopeGroupId %>,
                        folderId: <%= folderId %>,
                        tempFolderName: 'com.liferay.portlet.documentlibrary.action.EditFileEntryAction'
                    }
                },
                uploadFile: '<liferay-portlet:actionURL doAsUserId="<%= user.getUserId() %>"><portlet:param name="struts_action" value="/document_library/edit_file_entry" /><portlet:param name="<%= Constants.CMD %>" value="<%= Constants.ADD_TEMP %>" /><portlet:param name="folderId" value="<%= String.valueOf(folderId) %>" /></liferay-portlet:actionURL>&ticketKey=<%= ticket.getKey() %><liferay-ui:input-permissions-params modelName="<%= DLFileEntryConstants.getClassName() %>" />'
            }
        );
    </aui:script>

Hope this helps.

Upvotes: 2

Related Questions