Foren

add file programmatically into liferay

thumbnail
elias saliba, geändert vor 11 Jahren.

add file programmatically into liferay

New Member Beiträge: 24 Beitrittsdatum: 16.07.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: add file programmatically into liferay

Liferay Master Beiträge: 803 Beitrittsdatum: 10.03.08 Neueste Beiträge
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 ., geändert vor 11 Jahren.

RE: add file programmatically into liferay

Liferay Master Beiträge: 522 Beitrittsdatum: 29.08.11 Neueste Beiträge
check out
com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.updateStatus(....)
thumbnail
elias saliba, geändert vor 11 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 24 Beitrittsdatum: 16.07.12 Neueste Beiträge
thank you for your help but your solutions doesn't work.
do you have another solutions??
thumbnail
elias saliba, geändert vor 11 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 24 Beitrittsdatum: 16.07.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: add file programmatically into liferay

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
So did you try updateStatus as Paul suggested.
thumbnail
elias saliba, geändert vor 11 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 24 Beitrittsdatum: 16.07.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: add file programmatically into liferay

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
Did you start workflow?

WorkflowHandlerRegistryUtil.startWorkflowInstance
thumbnail
elias saliba, geändert vor 11 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 24 Beitrittsdatum: 16.07.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: add file programmatically into liferay

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: add file programmatically into liferay (Antwort)

New Member Beiträge: 24 Beitrittsdatum: 16.07.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: add file programmatically into liferay

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
Sorry for misguiding you. Good to hear that you have it working now. :-)
thumbnail
elias saliba, geändert vor 11 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 24 Beitrittsdatum: 16.07.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 12 Beitrittsdatum: 11.01.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 24 Beitrittsdatum: 16.07.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 12 Beitrittsdatum: 11.01.12 Neueste Beiträge
thank you for the help it is working now
Natasa Bulatovic, geändert vor 10 Jahren.

RE: add file programmatically into liferay

Junior Member Beiträge: 28 Beitrittsdatum: 07.06.11 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 13 Beitrittsdatum: 06.11.13 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: add file programmatically into liferay

Junior Member Beiträge: 66 Beitrittsdatum: 28.08.12 Neueste Beiträge
Thanks Elias, this post saved me 1+ days of headaches.
Alfresco_Liferay developer, geändert vor 9 Jahren.

RE: add file programmatically into liferay

New Member Beiträge: 18 Beitrittsdatum: 22.09.14 Neueste Beiträge
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, geändert vor 8 Jahren.

RE: add file programmatically into liferay

Junior Member Beiträge: 92 Beitrittsdatum: 29.07.14 Neueste Beiträge
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, geändert vor 7 Jahren.

RE: add file programmatically into liferay

New Member Beitrag: 1 Beitrittsdatum: 21.01.16 Neueste Beiträge
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