Fórumok
add file programmatically into liferay
elias saliba, módosítva 11 év-val korábban
add file programmatically into liferay
New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzések
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);
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);
Jignesh Vachhani, módosítva 11 év-val korábban
RE: add file programmatically into liferay
Liferay Master Bejegyzések: 803 Csatlakozás dátuma: 2008.03.10. Legújabb bejegyzések
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.
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.
Paul ., módosítva 11 év-val korábban
RE: add file programmatically into liferay
Liferay Master Bejegyzések: 522 Csatlakozás dátuma: 2011.08.29. Legújabb bejegyzések
check out
com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.updateStatus(....)
elias saliba, módosítva 11 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzések
thank you for your help but your solutions doesn't work.
do you have another solutions??
do you have another solutions??
elias saliba, módosítva 11 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzések
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??
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??
Hitoshi Ozawa, módosítva 11 év-val korábban
RE: add file programmatically into liferay
Liferay Legend Bejegyzések: 7942 Csatlakozás dátuma: 2010.03.24. Legújabb bejegyzések
So did you try updateStatus as Paul suggested.
elias saliba, módosítva 11 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzésekHitoshi 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..
Hitoshi Ozawa, módosítva 11 év-val korábban
RE: add file programmatically into liferay
Liferay Legend Bejegyzések: 7942 Csatlakozás dátuma: 2010.03.24. Legújabb bejegyzések
Did you start workflow?
WorkflowHandlerRegistryUtil.startWorkflowInstance
WorkflowHandlerRegistryUtil.startWorkflowInstance
elias saliba, módosítva 11 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzésekHitoshi Ozawa:
Did you start workflow?
WorkflowHandlerRegistryUtil.startWorkflowInstance
no can you explain to me what is the necessity of this?? thank you
Hitoshi Ozawa, módosítva 11 év-val korábban
RE: add file programmatically into liferay
Liferay Legend Bejegyzések: 7942 Csatlakozás dátuma: 2010.03.24. Legújabb bejegyzések
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.
If you have "Liferay in Action" I think there's an explanation in it.
elias saliba, módosítva 11 év-val korábban
RE: add file programmatically into liferay (Válasz)
New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzések
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(...);
thank you all for your help. i added a file an then updated programmatically with the same values, and it works!
DLFileEntryLocalServiceUtil.updateFileEntry(...);
Hitoshi Ozawa, módosítva 11 év-val korábban
RE: add file programmatically into liferay
Liferay Legend Bejegyzések: 7942 Csatlakozás dátuma: 2010.03.24. Legújabb bejegyzések
Sorry for misguiding you. Good to hear that you have it working now. :-)
elias saliba, módosítva 11 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzésekHitoshi 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, módosítva 11 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 12 Csatlakozás dátuma: 2012.01.11. Legújabb bejegyzések
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
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
elias saliba, módosítva 11 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzéseksandip 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, módosítva 11 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 12 Csatlakozás dátuma: 2012.01.11. Legújabb bejegyzések
thank you for the help it is working now
Natasa Bulatovic, módosítva 10 év-val korábban
RE: add file programmatically into liferay
Junior Member Bejegyzések: 28 Csatlakozás dátuma: 2011.06.07. Legújabb bejegyzések
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
@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, módosítva 10 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 13 Csatlakozás dátuma: 2013.11.06. Legújabb bejegyzések
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
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, módosítva 10 év-val korábban
RE: add file programmatically into liferay
Junior Member Bejegyzések: 66 Csatlakozás dátuma: 2012.08.28. Legújabb bejegyzések
Thanks Elias, this post saved me 1+ days of headaches.
Alfresco_Liferay developer, módosítva 9 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzések: 18 Csatlakozás dátuma: 2014.09.22. Legújabb bejegyzések
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
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
Enrique Valdes Lacasa, módosítva 8 év-val korábban
RE: add file programmatically into liferay
Junior Member Bejegyzések: 92 Csatlakozás dátuma: 2014.07.29. Legújabb bejegyzésekelias 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, módosítva 7 év-val korábban
RE: add file programmatically into liferay
New Member Bejegyzés: 1 Csatlakozás dátuma: 2016.01.21. Legújabb bejegyzések
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
Someone help me please?
Thank you