Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
shrikanth k shrikanth
How to upload image in database
December 26, 2013 1:52 AM
Answer

shrikanth k shrikanth

Rank: Junior Member

Posts: 97

Join Date: December 10, 2013

Recent Posts

hello frds,
i have simple requirment i want to upload image in mysql database from jsp to action class as well as i want to retrive image from databse and show to another jsp plz help me.
Subhash Pavuskar
RE: How to upload image in database
December 26, 2013 10:54 AM
Answer

Subhash Pavuskar

Rank: Regular Member

Posts: 234

Join Date: March 12, 2012

Recent Posts

https://www.liferay.com/community/forums/-/message_boards/message/21627007
shrikanth k shrikanth
RE: How to upload image in database
December 27, 2013 12:44 AM
Answer

shrikanth k shrikanth

Rank: Junior Member

Posts: 97

Join Date: December 10, 2013

Recent Posts

i didn't get from this link can u plz send code of u..
Muhammed Shafeek V
RE: How to upload image in database
December 27, 2013 2:37 AM
Answer

Muhammed Shafeek V

Rank: Regular Member

Posts: 123

Join Date: July 21, 2013

Recent Posts

Hi brother, try this

<portlet:actionURL var="uploadFilesURL" name="UploadFiles" />

<liferay-ui:error key="image-size-exceeded"
message="error-image-size-exceeded"/>

<aui:form action="<%= uploadFilesURL %>" enctype="multipart/form-data">
<aui:input type="hidden" name="bookId" value="<%= bookId %>"/>
<aui:input type="hidden" name="redirectURL"
value="<%= redirectURL %>"/>
<aui:input name="coverImage" type="file">
<aui:validator name="acceptFiles">
'jpg, png'
</aui:validator>
</aui:input>



<aui:button type="submit"/>
</aui:form>



public boolean processCommand(PortletRequest portletRequest,
PortletResponse portletResponse)
throws PortletException {

ActionRequest actionRequest = (ActionRequest) portletRequest;
ActionResponse actionResponse = (ActionResponse) portletResponse;

UploadPortletRequest uploadRequest =
PortalUtil.getUploadPortletRequest(actionRequest);

File coverImage = uploadRequest.getFile("coverImage");


return true;
}


And if you want to save that image into db use Image table of liferay.
shrikanth k shrikanth
RE: How to upload image in database
December 27, 2013 3:47 AM
Answer

shrikanth k shrikanth

Rank: Junior Member

Posts: 97

Join Date: December 10, 2013

Recent Posts

thanks for replying...........
sir i want to insert image in databse iam not geting how should i send to databse can u plz help me plz send code tht
Ritresh Girdhar
RE: How to upload image in database
December 27, 2013 3:51 AM
Answer

Ritresh Girdhar

Rank: Junior Member

Posts: 67

Join Date: July 15, 2011

Recent Posts

shrikanth shrikanth:
thanks for replying...........
sir i want to insert image in databse iam not geting how should i send to databse can u plz help me plz send code tht



Try this "http://stackoverflow.com/questions/18821813/upload-using-servlet-java-netbean-to-mysql-database"

But this is not best practice to save image in database, You should use some JSR 170,or place image in file system and add their path in db.
shrikanth k shrikanth
RE: How to upload image in database
December 27, 2013 4:37 AM
Answer

shrikanth k shrikanth

Rank: Junior Member

Posts: 97

Join Date: December 10, 2013

Recent Posts

i wnt to upload my image using service builder
Meera Prince
RE: How to upload image in database
December 27, 2013 7:42 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 838

Join Date: February 8, 2011

Recent Posts

HI
I have used BLOB data type in service builder its working success fully..
The following is example portlet and information use BLOB data type in service builder
I have done this to 6.2 portal and same you can do for other version it will work as for my guess..

http://www.liferaysavvy.com/2013/12/using-blob-data-type-in-liferay-service.html


Regards,

Meera Prince

http://www.liferaysavvy.com
shrikanth k shrikanth
RE: How to upload image in database
December 27, 2013 8:00 PM
Answer

shrikanth k shrikanth

Rank: Junior Member

Posts: 97

Join Date: December 10, 2013

Recent Posts

thanks for replying after adding.........how can i retrive to another jsp ans show to another jsp
Meera Prince
RE: How to upload image in database
December 27, 2013 8:35 PM
Answer

Meera Prince

Rank: Liferay Master

Posts: 838

Join Date: February 8, 2011

Recent Posts

Hi Try this

import java.sql.Blob;
import java.io.OutputStream;


Photo photo=PhotoLocalServiceUtil.getPhoto(1);
Blob image=photo.getData();
byte[ ] imgData=image.getBytes(1,(int)image.length());
response.setContentType("image/jpg");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
shrikanth k shrikanth
RE: How to upload image in database
December 28, 2013 8:22 AM
Answer

shrikanth k shrikanth

Rank: Junior Member

Posts: 97

Join Date: December 10, 2013

Recent Posts

sir this code should i put in jsp.bcoz i want to show image in jsp so how can i show to jsp.
shrikanth k shrikanth
RE: How to upload image in database
December 28, 2013 8:46 AM
Answer

shrikanth k shrikanth

Rank: Junior Member

Posts: 97

Join Date: December 10, 2013

Recent Posts

<column name="data" type="Blob" />

Blob is not valid data type in version 6.2 so plz help me
Meera Prince
RE: How to upload image in database
December 28, 2013 8:48 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 838

Join Date: February 8, 2011

Recent Posts

Hi
I have done sample portlet u can download see the code...

http://www.liferaysavvy.com/2013/12/using-blob-data-type-in-liferay-service.html


Regards,
Meera Prince
shrikanth k shrikanth
RE: How to upload image in database
December 28, 2013 10:42 PM
Answer

shrikanth k shrikanth

Rank: Junior Member

Posts: 97

Join Date: December 10, 2013

Recent Posts

sir ur code is not working on my laptop blob data type error is throwing plz help me
Meera Prince
RE: How to upload image in database
December 29, 2013 5:24 PM
Answer

Meera Prince

Rank: Liferay Master

Posts: 838

Join Date: February 8, 2011

Recent Posts

Hi

What is error in log please send me some deatiled description and screen shot..

Use portal Version 6.2 and Plugins SDK 6.2 +Tomcat 7.x and MySQL 5.1.

Go through following link and set up environment as guided in the article. i made it for same environment...

http://www.liferaysavvy.com/2013/12/liferay-62-portal-development.html


Regards,
Meera Prince.