Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Using Blob/Clob type in liferay Seeya S Kudtarker March 20, 2013 9:36 PM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 20, 2013 10:10 PM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 20, 2013 10:36 PM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 20, 2013 10:40 PM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 20, 2013 10:42 PM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 20, 2013 11:57 PM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 20, 2013 11:03 PM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 20, 2013 11:40 PM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 20, 2013 11:58 PM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 21, 2013 12:13 AM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 21, 2013 12:22 AM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 21, 2013 12:31 AM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 21, 2013 12:34 AM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 21, 2013 12:38 AM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 21, 2013 1:59 AM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 22, 2013 9:26 PM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 24, 2013 9:37 AM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 24, 2013 10:05 PM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 24, 2013 11:29 PM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 24, 2013 11:38 PM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 24, 2013 11:49 PM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 25, 2013 12:00 AM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 25, 2013 2:51 AM
RE: Using Blob/Clob type in liferay Mohammad Azharuddin March 25, 2013 8:57 AM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 27, 2013 7:06 AM
RE: Using Blob/Clob type in liferay Seeya S Kudtarker March 23, 2013 2:44 AM
Seeya S Kudtarker
Using Blob/Clob type in liferay
March 20, 2013 9:36 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 20, 2013 10:10 PM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

HI

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

Rgards
azhar
Seeya S Kudtarker
RE: Using Blob/Clob type in liferay
March 20, 2013 10:36 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 20, 2013 10:40 PM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

Hi
Yes in LR 6.1.x... .And which liferay version you are using..?
Regrads
Seeya S Kudtarker
RE: Using Blob/Clob type in liferay
March 20, 2013 10:42 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 20, 2013 11:57 PM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 20, 2013 11:03 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 20, 2013 11:40 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 20, 2013 11:58 PM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

In your Jsp
And previous answer is edited..check it out
Seeya S Kudtarker
RE: Using Blob/Clob type in liferay
March 21, 2013 12:13 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 21, 2013 12:22 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 21, 2013 12:31 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 21, 2013 12:34 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

And yeah if I declare fileEntryId as int it will need to be initialised..
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 21, 2013 12:38 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 21, 2013 1:59 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 22, 2013 9:26 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

How do I get the finalEntryId if I wan to?
Seeya S Kudtarker
RE: Using Blob/Clob type in liferay
March 23, 2013 2:44 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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.
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 24, 2013 9:37 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 24, 2013 10:05 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 24, 2013 11:29 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 24, 2013 11:38 PM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 24, 2013 11:49 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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 ?
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 25, 2013 12:00 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 25, 2013 2:51 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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?
Mohammad Azharuddin
RE: Using Blob/Clob type in liferay
March 25, 2013 8:57 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 458

Join Date: September 17, 2012

Recent Posts

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
RE: Using Blob/Clob type in liferay
March 27, 2013 7:06 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Thanks for the code.
Haven't tried it yet but will let you know once I get it right

Regards

Seeya