gpt4 book ai didi

liferay - 以编程方式将图像添加到 Liferay 文档库 6.1 版

转载 作者:行者123 更新时间:2023-12-04 02:54:02 24 4
gpt4 key购买 nike

在 Liferay6.1 中,我想以编程方式将图像添加到文档库中?

这是我想通过它将图像添加到文档库中的主要方法:

public class ImgGallery {
public static void main(String[] args) throws SystemException, FileNotFoundException {
byte[] bytes = new byte[0];
File srcfile = new File("C:\\Users\\my-pc\\Pictures\\extra\\myPhoto.jpg");
InputStream in = new FileInputStream(srcfile);
long repositoryId = 10180;
long folderId = 10651;
Map<String, Fields> fieldsMap = new HashMap<String, Fields>();
DLFileEntryLocalServiceUtil.addFileEntry(
10196, repositoryId, repositoryId, folderId,
"filename", MimeTypesUtil.getContentType("behnaz.jpg"),
"title", "description", "changeLog", 0, fieldsMap,
srcfile, null, bytes.length, serviceContext
);
}
}

这不起作用 - 我不知道向 DLFileEntryLocalServiceUtil.addFileEntry 提供什么参数?

最佳答案

用于将文件添加到 Liferay 文档库

您将需要一个文件夹,您可以在 liferay 控制面板中创建它,我的文件夹是 TestFolder。您可以使用 DLFolderLocalServiceUtil.getFolder 搜索它。您需要 dlfileentrytypes。我希望我们能从中了解其余的。您需要添加文件条目,然后您需要更新它才能获得批准。

ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
File file = uploadRequest.getFile("uploadFile");
DLFileEntry fileEntry = null;
Long lessonId = ParamUtil.getLong(request, "lid");
Lesson lll = LessonLocalServiceUtil.getLesson(lessonId);
String lesName = URLEncoder.encode(lll.getName(themeDisplay.getLocale()));
Date da = new Date();
String ext = FileUtil.getExtension(file.getName());
String dat = new SimpleDateFormat("yyyy-MM-dd").format(da);

String title = lesName + "-" + dat + "." + ext;
long portraitId = themeDisplay.getUser().getPortraitId();
byte[] imageBytes = FileUtil.getBytes(file);
InputStream is = new ByteArrayInputStream(imageBytes);
PortletPreferences preferences = request.getPreferences();
String nameRo=uploadRequest.getParameter("nameRO");
String nameEn=uploadRequest.getParameter("name");

DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "TestFolder");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(), request);
List<DLFileEntryType> tip = DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(DLUtil.getGroupIds(themeDisplay));

fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(themeDisplay.getUserId(),
themeDisplay.getScopeGroupId(),
themeDisplay.getScopeGroupId(),
dlFolder.getFolderId(),
file.getName(),
MimeTypesUtil.getContentType(file),
title,
request.getParameter("name"),
"",
tip.get(0).getFileEntryTypeId(),
null,
file,
is,
file.getTotalSpace(),
serviceContext);

DLFileEntryLocalServiceUtil.updateFileEntry(
themeDisplay.getUserId(),
fileEntry.getFileEntryId(),
file.getName(),
MimeTypesUtil.getContentType(file),
title,
"",
"",
true,
tip.get(0).getPrimaryKey(),
null,
file,
is,
file.getTotalSpace(),
serviceContext);

编辑 :
要访问文件条目下载网址,您可以使用
DLFileEntry dlf = DLFileEntryLocalServiceUtil.getDLFileEntry(f.get(i).getFileEntryId());
<a href='<%=themeDisplay.getPortalURL()+"/c/document_library/get_file?uuid="+DL.getUuid()+"&groupId="+themeDisplay.getScopeGroupId() %>' download>
Download </a>

关于liferay - 以编程方式将图像添加到 Liferay 文档库 6.1 版,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17009170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com