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

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

我需要将上传的文件保存在Document&的子目录中.来自Web表单portlet的liferay中的媒体文件夹. 我已经扩展了Web Form 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:09:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   目录   API   Liferay   Document

发布评论

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

>www.elefans.com

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