Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Liferay 7.2 - How to store images in my Database
Hi,
I want to add a feature to my website, but I am not sure what would be the best approach for this.
I have created a portlet to add a Product Object to my database through a Form. The submit button calls an ActionURL and in my Java class I use the Service Builder to add the new Product to my database. This is working perfect! But I also would like to add images to this product creation. So my idea would be to have a Div on my portlet that let's you upload multiple images with a preview and after the upload register the location of those images on my database to show them in the future.
So, my questions are:
Does Liferay have a dedicated folder where I could store my files uploaded? And how should I use them?
I don't think that Liferay has a native multiple image upload widget, so what would be the best approach to add one of these?
I want to add a feature to my website, but I am not sure what would be the best approach for this.
I have created a portlet to add a Product Object to my database through a Form. The submit button calls an ActionURL and in my Java class I use the Service Builder to add the new Product to my database. This is working perfect! But I also would like to add images to this product creation. So my idea would be to have a Div on my portlet that let's you upload multiple images with a preview and after the upload register the location of those images on my database to show them in the future.
So, my questions are:
Does Liferay have a dedicated folder where I could store my files uploaded? And how should I use them?
I don't think that Liferay has a native multiple image upload widget, so what would be the best approach to add one of these?
Hi ,
For uploading the document and saving it in Liferay DMS you can refer below referencehttp://liferayiseasy.blogspot.com/2015/07/folder-and-file-upload-programmatically.html.
For doing multiple uploads you can do it using liferay-upload script You can refer below code and url
https://github.com/liferay/liferay-portal/blob/7.2.x/modules/apps/document-library/document-library-web/src/main/resources/META-INF/resources/document_library/upload_multiple_file_entries.jsp
For uploading the document and saving it in Liferay DMS you can refer below referencehttp://liferayiseasy.blogspot.com/2015/07/folder-and-file-upload-programmatically.html.
For doing multiple uploads you can do it using liferay-upload script You can refer below code and url
https://github.com/liferay/liferay-portal/blob/7.2.x/modules/apps/document-library/document-library-web/src/main/resources/META-INF/resources/document_library/upload_multiple_file_entries.jsp
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
Hi Mohammed,
I was following your first link to create a documents and media folder and ended up with this:
This is creating the folder perfectly. The problem is: in my portal if I go to Content & Data -> Documents and Media -> Select the created folder and try to move it to the recycle bin, my request fails to complete. This doesn't happens if I create a folder on my portal instead of creating it programmatically. Any clue why this is happening? Am I passing a wrong param?
I was following your first link to create a documents and media folder and ended up with this:
public void addProduct(ActionRequest request, ActionResponse response) throws PortalException, FileNotFoundException {
ThemeDisplay theme = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
if (!folderExists(theme)) addFolder(request, theme);
}
private boolean folderExists(ThemeDisplay theme) {
if (DLFolderLocalServiceUtil.fetchFolder(theme.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Product Images") == null) return false;
else return true;
}
private void addFolder(ActionRequest request, ThemeDisplay theme) throws PortalException {
long userId = theme.getUserId();
long groupId = theme.getScopeGroupId();
long repositoryId = theme.getScopeGroupId();
long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
String folderName = "Product Images";
String folderDescription = "Folder to store product images";
ServiceContext context = ServiceContextFactory.getInstance(DLFolder.class.getName(), request);
DLFolderLocalServiceUtil.addFolder(userId, groupId, repositoryId, false, parentFolderId, folderName, null, false, context);
}
This is creating the folder perfectly. The problem is: in my portal if I go to Content & Data -> Documents and Media -> Select the created folder and try to move it to the recycle bin, my request fails to complete. This doesn't happens if I create a folder on my portal instead of creating it programmatically. Any clue why this is happening? Am I passing a wrong param?
Hi, Can you please share the error log your getting when deleting the folder.I would suggest you to use below api for adding folder
DLAppLocalServiceUtil.addFolder(userId, repositoryId, parentFolderId, name, description, serviceContext)
Hi,
Looks like by using the DLAppLocalServiceUtil I am able to delete the created folder. Thanks a lot!
Looks like by using the DLAppLocalServiceUtil I am able to delete the created folder. Thanks a lot!
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™