Liferay DLFileEntryLocalServiceUtil.addFileEntry d

2020-06-24 05:33发布

I have a custom portlet which provides a form where the user can upload files. The uploaded file should be stored in the Documents and Media Portlet. I am creating the file entry using DLFileEntryLocalServiceUtil.addFileEntry. The file is succesfully uploaded and the record in DLFileEntry table is created, but in the AssetEntry table no new record is created. I suppose Liferay should create it automatically, am I wrong? Where could be the error?

This is my code:

DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(user.getUserId(),
    groupId,
    groupId, //repositoryId,
        folder.getFolderId(),
    fName,
    mimeType,
    title,
    "", //description
    "", //changeLog,
    0,  //fileEntryTypeId
    null,   //fieldsMaps
    file,
    null,   //inputstream
    file.length(),
    serviceContext);

I get the form data from the UploadPortletRequest object ( UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest); )

I have the following ServiceContext:

ServiceContext serviceContext = new ServiceContext();
long[] assetCategoryIds = new long[assetCategoryIdsList.size()];
for (int i = 0; i < assetCategoryIdsList.size(); i++) {
    assetCategoryIds[i] = assetCategoryIdsList.get(i);
}
serviceContext.setAssetCategoryIds(assetCategoryIds);
serviceContext.setScopeGroupId(groupId);
if(!tagNames.equals("")) {
    serviceContext.setAssetTagNames(tagNames.split(","));
}

2条回答
来,给爷笑一个
2楼-- · 2020-06-24 05:57

It's not enough calling only DLFileEntryLocalServiceUtil.addFileEntry

After addFileEntry call DLFileEntryLocalServiceUtil.updateStatus(userId, fileVersionId, WorkflowConstants.STATUS_APPROVED, emptyMap, serviceContext);

With this method the AssetEntry is created and published

查看更多
Viruses.
3楼-- · 2020-06-24 06:05

Did you check this property in your portal -

#asset.renderer.enabled.com.liferay.portlet.documentlibrary.asset.DLFileEntryAssetRendererFactory=

查看更多
登录 后发表回答