【问题标题】:Multiple file upload in Liferay 6.1Liferay 6.1 中的多文件上传
【发布时间】:2012-06-08 04:13:39
【问题描述】:

有没有人在 Liferay 6.1 中尝试过多个文件上传。我试图以与 6.0 相同的方式进行操作,但失败得很厉害。我看到页面左上角的开始链接而不是 portlet。当我单击它并选择一些文件时,控件不会转到我的 portlet。我检查了我的 portlet.xml 并验证了 portlet-class 是否正确。这是jsp中的sn-p

<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>

这是我的 portlet 的 processAction 方法

@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");
        }

    }

【问题讨论】:

  • 你能告诉我们开发者控制台中发生了什么吗?
  • 它说 tempFileURL 未定义 [Break On This Error] ...empFileURL['method'](tempFileURL['params'], A.bind('_formatTempFiles', instance)...
  • 奇怪的错误,是JS引擎错误。是否包含所有引擎文件?
  • 你能显示 Upload.js 文件吗? ypu 会改变它吗(upload.js)?
  • 据我所知,我不必在我的 portlet 中包含 upload.js。它的内容应该很容易从门户获得。我没有更改upload.js。你想要来自 ROOT 的 upload.js?

标签: liferay


【解决方案1】:

您能否检查您的&lt;aui:script&gt; 是否正确,下面是 html/portlet/document_library/upload_multiple_file_entries.jsp 中显示的内容,我认为您缺少属性 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>

希望这会有所帮助。

【讨论】:

  • tempFileURL 的用途是什么以及如何从 portlet 中添加它。从外观上看,他们正在尝试使用javascript服务api调用服务方法,我没有这样的要求
  • tempFileURL 用于获取临时存储在服务器上某个位置(由 tempFolderName 定义)上的文件的名称,直到您实际将其保存为 DLFileEntry,即即使您没有明确保存文件,Liferay 会在您下次进入上传页面时显示这些文件。它返回存储(未保存)的文件名称(getTempFileEntryNames)以在 UI 上显示,以便您可以通过文件名旁边的复选框选择它,然后单击保存以保存所选的特定文件。跨度>
  • 要识别Liferay.Service.DL.DLApp.getTempFileEntryNames,不要忘记像这样包含service.js:&lt;script src="/html/js/liferay/service.js" language="JavaScript"&gt; &lt;/script&gt; 或在liferay-portlet.xml 中像这样声明它:&lt;footer-portal-javascript&gt;/html/js/liferay/service.js&lt;/footer-portal-javascript&gt;
猜你喜欢
  • 2014-12-17
  • 1970-01-01
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-31
  • 2013-07-28
相关资源
最近更新 更多