Foros de discusión

add file programmatically into liferay

thumbnail
elias saliba, modificado hace 11 años.

add file programmatically into liferay

New Member Mensajes: 24 Fecha de incorporación: 16/07/12 Mensajes recientes
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, modificado hace 11 años.

RE: add file programmatically into liferay

Liferay Master Mensajes: 803 Fecha de incorporación: 10/03/08 Mensajes recientes
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 ., modificado hace 11 años.

RE: add file programmatically into liferay

Liferay Master Mensajes: 522 Fecha de incorporación: 29/08/11 Mensajes recientes
check out
com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.updateStatus(....)
thumbnail
elias saliba, modificado hace 11 años.

RE: add file programmatically into liferay

New Member Mensajes: 24 Fecha de incorporación: 16/07/12 Mensajes recientes
thank you for your help but your solutions doesn't work.
do you have another solutions??
thumbnail
elias saliba, modificado hace 11 años.

RE: add file programmatically into liferay

New Member Mensajes: 24 Fecha de incorporación: 16/07/12 Mensajes recientes
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, modificado hace 11 años.

RE: add file programmatically into liferay

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
So did you try updateStatus as Paul suggested.
thumbnail
elias saliba, modificado hace 11 años.

RE: add file programmatically into liferay

New Member Mensajes: 24 Fecha de incorporación: 16/07/12 Mensajes recientes
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, modificado hace 11 años.

RE: add file programmatically into liferay

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Did you start workflow?

WorkflowHandlerRegistryUtil.startWorkflowInstance
thumbnail
elias saliba, modificado hace 11 años.

RE: add file programmatically into liferay

New Member Mensajes: 24 Fecha de incorporación: 16/07/12 Mensajes recientes
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, modificado hace 11 años.

RE: add file programmatically into liferay

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
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, modificado hace 11 años.

RE: add file programmatically into liferay (Respuesta)

New Member Mensajes: 24 Fecha de incorporación: 16/07/12 Mensajes recientes
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, modificado hace 11 años.

RE: add file programmatically into liferay

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Sorry for misguiding you. Good to hear that you have it working now. :-)
thumbnail
elias saliba, modificado hace 11 años.

RE: add file programmatically into liferay

New Member Mensajes: 24 Fecha de incorporación: 16/07/12 Mensajes recientes
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, modificado hace 11 años.

RE: add file programmatically into liferay

New Member Mensajes: 12 Fecha de incorporación: 11/01/12 Mensajes recientes
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, modificado hace 11 años.

RE: add file programmatically into liferay

New Member Mensajes: 24 Fecha de incorporación: 16/07/12 Mensajes recientes
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, modificado hace 11 años.

RE: add file programmatically into liferay

New Member Mensajes: 12 Fecha de incorporación: 11/01/12 Mensajes recientes
thank you for the help it is working now
Natasa Bulatovic, modificado hace 10 años.

RE: add file programmatically into liferay

Junior Member Mensajes: 28 Fecha de incorporación: 7/06/11 Mensajes recientes
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, modificado hace 10 años.

RE: add file programmatically into liferay

New Member Mensajes: 13 Fecha de incorporación: 6/11/13 Mensajes recientes
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, modificado hace 10 años.

RE: add file programmatically into liferay

Junior Member Mensajes: 66 Fecha de incorporación: 28/08/12 Mensajes recientes
Thanks Elias, this post saved me 1+ days of headaches.
Alfresco_Liferay developer, modificado hace 9 años.

RE: add file programmatically into liferay

New Member Mensajes: 18 Fecha de incorporación: 22/09/14 Mensajes recientes
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, modificado hace 8 años.

RE: add file programmatically into liferay

Junior Member Mensajes: 92 Fecha de incorporación: 29/07/14 Mensajes recientes
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, modificado hace 7 años.

RE: add file programmatically into liferay

New Member Mensaje: 1 Fecha de incorporación: 21/01/16 Mensajes recientes
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