留言板

add file programmatically into liferay

thumbnail
elias saliba,修改在11 年前。

add file programmatically into liferay

New Member 帖子: 24 加入日期: 12-7-16 最近的帖子
please help,

i'am creating a liferay portlet where i can upload document files and images. the upload process works well but every document or file uploaded have the status draft, and don't appears in the workflow tasks. how can i programmatically add a file with status Pending??

here is my code:

DLFileEntry dlFileEntry=DLFileEntryLocalServiceUtil.addFileEntry(themeDisplay.getUserId(),10179, repId, folId, fileName+".png", MimeTypesUtil.getContentType(fin), fileTitle, fileDesc, "sss",
entryType.getFileEntryTypeId()
,fieldsMap
,fin
,null
,fin.length()
,serviceContext);
thumbnail
Jignesh Vachhani,修改在11 年前。

RE: add file programmatically into liferay

Liferay Master 帖子: 803 加入日期: 08-3-10 最近的帖子
I haven't tried but as i have seen code of DLFileEntryLocalServiceImpl class and in that you just try to replace below code in public DLFileEntry addFileEntry( method

DLFileVersion dlFileVersion = addFileVersion(
user, dlFileEntry, serviceContext.getModifiedDate(now), extension,
mimeType, title, description, null, StringPool.BLANK,
fileEntryTypeId, fieldsMap, DLFileEntryConstants.VERSION_DEFAULT,
size, WorkflowConstants.STATUS_PENDING, serviceContext);

You can override this class using ext or hook.
thumbnail
Paul .,修改在11 年前。

RE: add file programmatically into liferay

Liferay Master 帖子: 522 加入日期: 11-8-29 最近的帖子
check out
com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.updateStatus(....)
thumbnail
elias saliba,修改在11 年前。

RE: add file programmatically into liferay

New Member 帖子: 24 加入日期: 12-7-16 最近的帖子
thank you for your help but your solutions doesn't work.
do you have another solutions??
thumbnail
elias saliba,修改在11 年前。

RE: add file programmatically into liferay

New Member 帖子: 24 加入日期: 12-7-16 最近的帖子
help me out please,

the main problem is that when i upload a file programmatically, its status is draft. and the file don't appear in the list of workflow. how can i change this??
thumbnail
Hitoshi Ozawa,修改在11 年前。

RE: add file programmatically into liferay

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
So did you try updateStatus as Paul suggested.
thumbnail
elias saliba,修改在11 年前。

RE: add file programmatically into liferay

New Member 帖子: 24 加入日期: 12-7-16 最近的帖子
Hitoshi Ozawa:
So did you try updateStatus as Paul suggested.



yes hitoshi i tried it :

DLFileEntry dlFileEntryUpdated = DLFileEntryLocalServiceUtil.updateStatus(themeDisplay.getUserId(), dlFileEntry.getFileVersion().getFileVersionId() ,WorkflowConstants.ACTION_PUBLISH, null, serviceContext);

the status of the file has been changed to "(pending)" but the problem is that i can't approve the file in the workflow..
thumbnail
Hitoshi Ozawa,修改在11 年前。

RE: add file programmatically into liferay

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
Did you start workflow?

WorkflowHandlerRegistryUtil.startWorkflowInstance
thumbnail
elias saliba,修改在11 年前。

RE: add file programmatically into liferay

New Member 帖子: 24 加入日期: 12-7-16 最近的帖子
Hitoshi Ozawa:
Did you start workflow?

WorkflowHandlerRegistryUtil.startWorkflowInstance



no can you explain to me what is the necessity of this?? thank you
thumbnail
Hitoshi Ozawa,修改在11 年前。

RE: add file programmatically into liferay

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
I think you can't approve it because you haven't started a workflow instance and assigned userId to it.
If you have "Liferay in Action" I think there's an explanation in it.
thumbnail
elias saliba,修改在11 年前。

RE: add file programmatically into liferay (答复)

New Member 帖子: 24 加入日期: 12-7-16 最近的帖子
i found the solution....
thank you all for your help. i added a file an then updated programmatically with the same values, and it works!

DLFileEntryLocalServiceUtil.updateFileEntry(...);
thumbnail
Hitoshi Ozawa,修改在11 年前。

RE: add file programmatically into liferay

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
Sorry for misguiding you. Good to hear that you have it working now. :-)
thumbnail
elias saliba,修改在11 年前。

RE: add file programmatically into liferay

New Member 帖子: 24 加入日期: 12-7-16 最近的帖子
Hitoshi Ozawa:
Sorry for misguiding you. Good to hear that you have it working now. :-)


no Hitoshi you didn't misguided me. thank you for your help it's a pleasure:-)
sandip niyogi,修改在11 年前。

RE: add file programmatically into liferay

New Member 帖子: 12 加入日期: 12-1-11 最近的帖子
hello ,
can you please tell me how to add files programatically in liferay document library
i have tried all the possible solution getting the value in dlfolder
then trying to add it through addfileentry.

"ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
String title = "Jit" + StringPool.UNDERLINE + file.getName();
DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
actionRequest);
till this much it is working fine
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, groupId, folderId, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, fileEntryTypeId ,fieldsMap, file, null, file.length(), serviceContext);
HERE THE PROBLEM STARTS
Can plese help me out with this that will be a great help .
THANKS IN ADVANCE
thumbnail
elias saliba,修改在11 年前。

RE: add file programmatically into liferay

New Member 帖子: 24 加入日期: 12-7-16 最近的帖子
sandip niyogi:
hello ,
can you please tell me how to add files programatically in liferay document library
i have tried all the possible solution getting the value in dlfolder
then trying to add it through addfileentry.

"ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
String title = "Jit" + StringPool.UNDERLINE + file.getName();
DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
actionRequest);
till this much it is working fine
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, groupId, folderId, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, fileEntryTypeId ,fieldsMap, file, null, file.length(), serviceContext);
HERE THE PROBLEM STARTS
Can plese help me out with this that will be a great help .
THANKS IN ADVANCE




you have to add a file and the update it without changing anything. here is the code->

DLFileEntry dlFileEntry=DLFileEntryLocalServiceUtil.addFileEntry(userId,10179, repId, folId, fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, "sss",
entryType.getFileEntryTypeId()
,fieldsMap
,fileInfo.getFile()
,null
,fileInfo.getFile().length()
,serviceContext);

DLFileEntryLocalServiceUtil.updateFileEntry(userId, dlFileEntry.getFileEntryId(), fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, comment, true, dlFileEntry.getFileEntryTypeId(), fieldsMap, fileInfo.getFile(), null, fileInfo.getFile().length(), serviceContext);
sandip niyogi,修改在11 年前。

RE: add file programmatically into liferay

New Member 帖子: 12 加入日期: 12-1-11 最近的帖子
thank you for the help it is working now
Natasa Bulatovic,修改在10 年前。

RE: add file programmatically into liferay

Junior Member 帖子: 28 加入日期: 11-6-7 最近的帖子
Thank you all, if this thread did not exist, i was lost to dig in again into source code for a very simple operation.
@LiferayDevelopers: why does one needs to call both methods?
The problem i had (until i finally called update method again): file was created, could even set it to Published, but could never update it again.

Tricky and time consuming ... Please do something to change it .

Best
Natasa
Joan Fluvia,修改在10 年前。

RE: add file programmatically into liferay

New Member 帖子: 13 加入日期: 13-11-6 最近的帖子
I did as mentioned: addFileEntry and then the updateFileEntry and the file is uploading as published correctly.
But when I try to access it directly with the URL: http://localhost:8080/documents/....pdf/...
It says that I have to log in (If I log in I can see it).
So I check the permissions in the DocumentLibrary and the permissions are ok. And just after checking the permissions (without saving, only clicking the permissions button) then I can access the file with the URL without asking me to log in. Anyone else with the same issue?

The way I initilize the ServiceContext is this:

public ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

I have a script that simulates clicking the permissions button for every document in the DocumentLibrary. But if someone offers a better approach...

Thanks,
Joan
Eric Smith,修改在10 年前。

RE: add file programmatically into liferay

Junior Member 帖子: 66 加入日期: 12-8-28 最近的帖子
Thanks Elias, this post saved me 1+ days of headaches.
Alfresco_Liferay developer,修改在9 年前。

RE: add file programmatically into liferay

New Member 帖子: 18 加入日期: 14-9-22 最近的帖子
Hi

I am new in liferay. please can any one copy aste whole logic of uploading file. I didn't know from where can i get my group id, folder id etc...
please help me..

Thank you
thumbnail
Enrique Valdes Lacasa,修改在8 年前。

RE: add file programmatically into liferay

Junior Member 帖子: 92 加入日期: 14-7-29 最近的帖子
elias saliba:
sandip niyogi:
hello ,
can you please tell me how to add files programatically in liferay document library
i have tried all the possible solution getting the value in dlfolder
then trying to add it through addfileentry.

"ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
String title = "Jit" + StringPool.UNDERLINE + file.getName();
DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
actionRequest);
till this much it is working fine
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, groupId, folderId, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, fileEntryTypeId ,fieldsMap, file, null, file.length(), serviceContext);
HERE THE PROBLEM STARTS
Can plese help me out with this that will be a great help .
THANKS IN ADVANCE




you have to add a file and the update it without changing anything. here is the code->

DLFileEntry dlFileEntry=DLFileEntryLocalServiceUtil.addFileEntry(userId,10179, repId, folId, fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, "sss",
entryType.getFileEntryTypeId()
,fieldsMap
,fileInfo.getFile()
,null
,fileInfo.getFile().length()
,serviceContext);

DLFileEntryLocalServiceUtil.updateFileEntry(userId, dlFileEntry.getFileEntryId(), fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, comment, true, dlFileEntry.getFileEntryTypeId(), fieldsMap, fileInfo.getFile(), null, fileInfo.getFile().length(), serviceContext);


Thank you Elias. This worked for me. As you said, the files were uploaded with the Draft status, since I guess they weren't added to the DB without calling the updateFileEntry() method. Your suggestions saved me a few hours, thanks!
domenico fiorilli,修改在7 年前。

RE: add file programmatically into liferay

New Member 发布: 1 加入日期: 16-1-21 最近的帖子
Hi all, I noticed that when I try an update of the file, metadata fields are not written to the database, in fact, if I try to exec my web services, its metadata fields are null.

Someone help me please?

Thank you