Fórumok

Using Blob/Clob type in liferay

Seeya S Kudtarker, módosítva 11 év-val korábban

Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
I have followed the follwing links:
http://vforliferay.blogspot.com/2010/12/fileupload-using-servicexml-file.html
http://www.liferay.com/community/wiki/-/wiki/Main/Customize+DB+Column+Sizes
and
http://www.liferay.com/community/forums/-/message_boards/message/21041278
for storing images. (by first declaring the datatype as strign and then modifying portlet-model-hints.xml file and running the services again.)But even after deploying the portlet when I check the database the datatype remains as Longtext instead of clob.
The images get uploaded but when I try to display the images I get the text.
I followed the steps mentioned in:
http://vforliferay.blogspot.com/2010/12/fileupload-using-servicexml-file.html
for uploading images.
How should I display images?

second approach:
Another way I tried is by directly declaring the datatype for column as blob but after running services it builds the services successfully but shows an error in package com.test.blob.upload in the blobuploadModelImpl class. the error is below highlighted in bold:
@Override
public void resetOriginalValues() {
blobuploadModelImpl._pictureBlobModel = null;
}
the suggestion is
change modifier of pictureBlobModel to static

Should I change the modifier to static in this case?

Which approach from the above two should I follow? Is there any other way to display the images from database? like I said earlier storing of images worked if I followed the first approach.

Kindly give suggestions

Regards

Seeya
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
HI

Why cant you use document library to store images...?

Rgards
azhar
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
mohammad azaruddin:

Thanks for your reply.

The Document library as in you mean the Documents and Media in the Control Panel, isn't it?

Regards
Seeya
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
Hi
Yes in LR 6.1.x... .And which liferay version you are using..?
Regrads
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
Thanks!
Liferay 6.1

And can you guide me how do i retrieve it when I need it in my portlet?
I want to display the images on the form

Regards

Seeya
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
create fileEntry object using fileEntryIdid
<%DLFileEntry fileEntry =DLFileEntryLocalServiceUtil.getFileEntry(fileEntryId);%>



<%String Download = "";
Download = themeDisplay.getPortalURL()
+ themeDisplay.getPathContext()
+ "/documents/"
+ themeDisplay.getScopeGroupId()
+ StringPool.SLASH
+ fileEntry .getFolderId()
+ StringPool.SLASH
+ HttpUtil.encodeURL(HtmlUtil.unescape(String
.valueOf(fileEntry .getTitle()))) + "?version="
+ fileEntry .getVersion();%>


AND use html to view
<a href="<%=Download%>">View Image</a>
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
mohammad azaruddin
Thanks!!

I will try this and let you know about my progress.
Kindly follow this thread when I reply.

Regards

Seeya
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
mohammad azaruddin

I am asking you a very basic question.

Where exactly am I supposed to write the following code you gave me?

create fileEntry object using fileEntryIdid
DLFileEntry fileEntry =DLFileEntryLocalServiceUtil.getFileEntry(fileEntryId)

String Download = "";
Download = themeDisplay.getPortalURL()
+ themeDisplay.getPathContext()
+ "/documents/"
+ themeDisplay.getScopeGroupId()
+ StringPool.SLASH
+ fileEntry .getFolderId()
+ StringPool.SLASH
+ HttpUtil.encodeURL(HtmlUtil.unescape(String
.valueOf(fileEntry .getTitle()))) + "?version="
+ fileEntry .getVersion();


<a href="<%=Download%>">View Image</a>


What I mean is whether I should write it in jsp or create a function in java class?

I am confused
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
In your Jsp
And previous answer is edited..check it out
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
mohammad azaruddin
Thanks that you are following up. I have been trying to solve this issue for past three days with blobs..

Here is my Jsp

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ page import = "com.liferay.portal.kernel.util.HtmlUtil" %>
<%@ page import = "com.liferay.portal.kernel.util.HttpUtil" %>
<%@ page import = "com.liferay.portal.kernel.util.StringPool" %>
<%@ page import = "com.liferay.portal.theme.ThemeDisplay" %>
<%@ page import = "com.liferay.portlet.documentlibrary.model.DLFileEntry" %>
<%@ page import = "com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil" %>
<%@ page import = "com.liferay.portal.theme.ThemeDisplay" %>
<%@ page import = "javax.portlet.RenderRequest" %>
<%@page import = "com.liferay.portal.kernel.util.WebKeys" %>
<%@page import = "javax.portlet.RenderRequest" %>
<portlet:defineObjects />

This is the <b>Test DisplayImages</b> portlet.


<%DLFileEntry fileEntry =DLFileEntryLocalServiceUtil.getFileEntry(fileEntryId);%>



<%String Download = "";
Download = ThemeDisplay.getPortalURL()
+ ThemeDisplay.getPathContext()
+ "/documents/"
+ ThemeDisplay.getScopeGroupId()
+ StringPool.SLASH
+ fileEntry .getFolderId()
+ StringPool.SLASH
+ HttpUtil.encodeURL(HtmlUtil.unescape(String
.valueOf(fileEntry .getTitle()))) + "?version="
+ fileEntry .getVersion();%>

<DOCTYPE HTML>
<html>
<head>
<title>Display image</title>
</head>

<body>
<a href="<%=Download%>">View Image</a>
</body>
</html>


And I am getting errrors:
for ThemeDisplay : Cannot make a static reference to the non-static method getPortalURL() from the type ThemeDisplay
for
fileEntryId : fileEntryId cannot be resolved to a variable

Should I declare fileEntryId as an int in the above code? And what aboutThemeDisplay?

Regards
Seeya
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
HI

1)create themeDisplay ThemeDisplay themeDisplay = (ThemeDisplay) request
.getAttribute(WebKeys.THEME_DISPLAY);


Use themeDisplay instead of ThemeDisplay

2)before download or view image u must upload image to document library either manually or programatically

And fileEnrtyId Unique id of image stored in Document library..it is stored in DLFileEntry table
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
mohammad azaruddin,
Yes I have image stored in DL
Ya I had figurd it out that fileEntryId will be the Id of the image that is stored. But it shows me error in the line:
<%DLFileEntry fileEntry =DLFileEntryLocalServiceUtil.getFileEntry(fileEntryId);%>

I have included the below package:
<%@ page import = "com.liferay.portlet.documentlibrary.model.DLFileEntry" %>

but still there is an error with fileEntryId saying that it cannot be resolved to a variable.
Do I need to declare it as int fileEntryId ?

Regards
Seeya
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
And yeah if I declare fileEntryId as int it will need to be initialised..
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
Hi
How you are storing image in document libray..?programatically or manually(using control panel)..?
and fileEntryId is variable which contain fileId of image you want to view/download..

For understanding the concept pass the fileid statically example 12233
regards
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
I am storing the images manually. Control Panel-Documents & Media.
I am still trying to figure out what is wrong with my code. It doesn't display any images
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
How do I get the finalEntryId if I wan to?
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
HI
if your adding file programatically u can save fileEntryId in your custom table too and use it whenever u want...As you are storing manually you have check database table DLFileEntry for the fileEntryId.....

Check this link for further detailDLFILE
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
mohammad azaruddin:

I got it working! Thanks for the timely help.
Yes I checked the databse entries and used them to display images and it worked.
I was getting some other error (invoker filter) tht is why I wasn't able to do anything.

I was actually thinking of doing what you said : "if your adding file programatically u can save fileEntryId in your custom table too and use it whenever u want"
I will do it programmatically!! Will try and let you know
Thanks for the help!!

Regards

Seeya
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
mohammad azaruddin:

I want to refer to fileEntry id from DLFileEntry table in my custom table say EmpData.
Here will be the snippet code service. xml for
<entity name="EmpData" local-service = "true" remote-service = "false">
<column name = "empId" type = "long" primary = "true"/>
<column name = "EmpName" type = "String"/>
<column name = "EmpAge" type = "String"/>
</entity>

Now how do I include fileEntryId of DLFileEntry table into my above custom table-EmpData.
Is it the way I have shown below

<entity name="EmpData" local-service = "true" remote-service = "false">
<column name = "empId" type = "long" primary = "true"/>
<column name = "EmpName" type = "String"/>
<column name = "EmpAge" type = "String"/>
<column name = "fileEntryId" type = "long" Entity = "com.liferay.portlet.documentlibrary.DLFileEntry"/>
</entity>

Or should I refer it the following way?

<entity name="EmpData" local-service = "true" remote-service = "false">
<column name = "empId" type = "long" primary = "true"/>
<column name = "EmpName" type = "String"/>
<column name = "EmpAge" type = "String"/>
<column name = "fileEntryId" type = "long" />
<refrence package path = "com.liferay.portlet.documentlibrary.DLFileEntry">
</entity>

Kindly help


Regards

Seeya
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
Hi

<entity name="EmpData" local-service = "true" remote-service = "false">
<column name = "empId" type = "long" primary = "true"/>
<column name = "EmpName" type = "String"/>
<column name = "EmpAge" type = "String"/>
<column name = "fileEntryId" type = "long" />
</entity>
And use setter method to store the fileEntryId in your action class..Same as you stote EmpName or EmpAge

Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
So don't I need to refer to DLFileEntry entity?
The code you showed above will create a field fileEntryId but how will it refer to DLFileEntry table?

Would you please explain? From what I understood it will only create a column fileEntryId like any other column.
How will this fileEntryId FROM EmpData refer to DLFileEntry ?
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
Hi here is code to add programatically.so while adding u create dlFileEntry object as shown below and and by using that object u can get the file entry id
dlFileEntry.getFileEntryId()

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);


refer the link
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
mohammad azaruddin:

It isn't working. How do I give folderId,repId in addEntry function?
It shows me error in hose parameters which are passed to addEntry function.
I take my input file as :
<input type = "file name = "imageupload"/>

Then in action class if I use getparameter(imageupload) I suppose I will get only the name of the file. I am not sure.

So how do I pass the image input by user to a java class?
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
Hi

step1:In jsp.
<%PortletURL addDocumentURL = renderResponse.createActionURL();
addDocumentURL .setParameter(ActionRequest.ACTION_NAME, "addToDocumentLibrary");
%>
<aui:form name="fm" id="fm" action="<%=addDocumentURL .toString()%>"
method="post" enctype="multipart/form-data">
<aui:input type="file" name="addfile"/>
<aui:input type="submit" name="Submit" value="Submit" label=""/>
</aui:form >



step2:submit the form .. it will go to action class method addToDocumentLibrary
public void addToDocumentLibrary(ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
.getAttribute(WebKeys.THEME_DISPLAY);
//create uploadPortletRequest object as it contain file
UploadPortletRequest uploadPortletRequest = PortalUtil
.getUploadPortletRequest(actionRequest);
//create serviceContext object
ServiceContext serviceContext = ServiceContextFactory
.getInstance(DLFileEntry.class.getName(), actionRequest);
//create DLfolder programatically

String name="write some name"
String description="description here"

Folder dlFolder = DLAppServiceUtil.addFolder(
themeDisplay.getScopeGroupId(), 0L,
name, description),
serviceContext);
String sourceFileName = uploadPortletRequest
.getFileName("addfile");


File file = uploadPortletRequest.getFile("addfile");
if (Validator.isNotNull(sourceFileName)) {
long size = uploadPortletRequest.getSize("addfile");
if (Validator.isNotNull(sourceFileName)
&& Validator.isNotNull(size)
&& Validator.isNotNull(file) && !file.exists()) {
file.createNewFile();
}
List<DLFolder> dlFolders = DLFolderLocalServiceUtil
.getCompanyFolders(themeDisplay.getCompanyId(), 0,
DLFolderLocalServiceUtil
.getDLFoldersCount());
long repositoryIds = 0L;
long groupId = 0L;
long folderId = 0L;
long fileEntryTypeId = 0L;
for (DLFolder folder : dlFolders) {
try {
if (folder.getName().equalsIgnoreCase(
dlFolder.getName())) {
folderId = folder.getFolderId();
repositoryIds = folder.getRepositoryId();
groupId = folder.getGroupId();
fileEntryTypeId = folder
.getDefaultFileEntryTypeId();
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
DLFileEntry dlFileEntry = null;
String sDate = simpleDateFormatForDL.format(new Date());
dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(
themeDisplay.getUserId(), groupId, repositoryIds,
folderId, sourceFileName,
MimeTypesUtil.getContentType(file), sourceFileName
, StringPool.BLANK,
StringPool.BLANK, fileEntryTypeId, null, file,
inputStream, size, serviceContext);
DLFileEntryLocalServiceUtil.updateFileEntry(
themeDisplay.getUserId(),
dlFileEntry.getFileEntryId(), sourceFileName,
MimeTypesUtil.getContentType(file), sourceFileName
, StringPool.BLANK,
StringPool.BLANK, true,
dlFileEntry.getFileEntryTypeId(), null, file, null,
file.length(), serviceContext);
}


Make sure that file title is unique
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
Thanks for the code.
Haven't tried it yet but will let you know once I get it right

Regards

Seeya
Seeya S Kudtarker, módosítva 11 év-val korábban

RE: Using Blob/Clob type in liferay

Regular Member Bejegyzések: 187 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
I solved the problem by adding :
DLFileEntry fileEntry = com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.getFileEntry(fileEntryId);

But now the portlet is not getting displayed.

In fact nothing is displayed when I click on the porltet in Control Panel.