使用 API 将文件保存到 liferay 6.1 中的 Document 目录

编程入门 行业动态 更新时间:2024-10-26 22:21:42
本文介绍了使用 API 将文件保存到 liferay 6.1 中的 Document 目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要将上传的文件保存在 Document & 的子目录中来自 web 表单 portlet 的 liferay 中的媒体文件夹.我已经扩展了 Web 表单 portlet 来执行此操作,但文件已成功上传到数据库 &不在 Document &媒体文件夹.我尝试使用以下代码将文件上传到文档目录中,但没有成功,请帮忙.

I need to save a uploaded file in sub directory of Document & Media folder in liferay from web-form portlet. I have extended the web Form portlet to do so, but file is getting uploaded successfully in database & not in Document & Media folder. I tried following code to upload the file in document directory but no success please help .

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

推荐答案

试试这个代码片段

ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); File file = uploadRequest.getFile("file"); String contentType = MimeTypesUtil.getContentType(file); InputStream inputStream = new FileInputStream(file); Folder folderName = DLAppLocalServiceUtil.getFolder(parentRepositoryId, parentFolderId, "Folder Name"); long folderId = folderName.getFolderId(); long repositoryId = folderName.getRepositoryId(); FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), repositoryId, folderId, file.getName(), contentType, "File Name", "description", "changeLog", inputStream, file.length(), serviceContext);

更多推荐

使用 API 将文件保存到 liferay 6.1 中的 Document 目录

本文发布于:2023-10-29 13:10:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   目录   API   liferay   Document

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!