我需要从 web-form portlet 将上传的文件保存在 liferay 中 Document & Media 文件夹的子目录中。
我已经扩展了 web 表单 portlet 来执行此操作,但文件已成功上传到数据库中,而不是 Document & Media 文件夹中。
我尝试使用以下代码将文件上传到文档目录中,但没有成功,请帮忙。
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
String title = file.getName();
DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),actionRequest);
Map<String, Fields> fieldsMap = new HashMap<String, Fields>();
long fileEntryTypeId = DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT;
FileInputStream inputStream = new FileInputStream(file);
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), 10153, dlFolder.getRepositoryId(),
dlFolder.getRepositoryId(), title, file.getContentType(), title, "fileDesc", "sss",
fileEntryTypeId, fieldsMap, file, inputStream, file.length(), serviceContext);
inputStream.close();
DLFileEntryLocalServiceUtil.updateFileEntry(themeDisplay.getUserId(), dlFileEntry.getFileEntryId(), title, file.getContentType(),
title, "fileDesc", "comment", true, dlFileEntry.getFileEntryTypeId(), fieldsMap, file, null, file.length(), serviceContext);