From: Dilan <dilan@waterfind.com.au>
To: pgsql-jdbc@postgresql.org
Subject: Dynamically Out put a image in Jsp
Date: Fri, 27 May 2005 11:09:30 +0930
Message-ID: <200505270137.j4R1bWMh029971@internal.waterfind.com.au> (raw)
In-Reply-To: <42967356.2060507@fastcrypt.com>
Hello,
I'm using psql 8.0.3-RH,
And using hibernate version 2.0.3 mapping,
I'm using hibernate to connect postgresql via java, and I'm trying to save a
image as a binary file,
When I upload, use this part of the class:
UploadTransferForm uForm = (UploadTransferForm) form; int
size=uForm.getFileUpload().getFileSize();
byte[] byteArr = new byte[size];
ActionErrors errors = new ActionErrors();
try {
//Create an input stream to read the uploaded file.
ByteArrayInputStream bytein = new
ByteArrayInputStream(uForm.getFileUpload().getFileData());
// Load the input stream into the byte Array.
bytein.read(byteArr);
// Close the input stream.
bytein.close();
// Load the byte[] into the content field.
uForm.setContent(byteArr);
} catch (Exception e) {
logger.error("Error adding image to the database", e);
}
Session sess = null;
AuthorityApprovalForms af = new AuthorityApprovalForms();
try {
sess = Waterfind.getSessionFactory().openSession();
} catch (net.sf.hibernate.HibernateException e) {
logger.error("Error opening hibernate session", e); }
try {
af.setImg(byteArr);
sess.save(af);
sess.flush();
} catch (Exception e) {
--
when i diplaying it
try {
AuthorityApprovalForms af = new AuthorityApprovalForms();
Long formId = new Long(request.getParameter("formId"));
af = AuthorityApprovalForms.getFormById(formId);
byte pic[] = af.getImg();
OutputStream out = response.getOutputStream();
out.write( pic );
} catch (IOException e) {
logger.error("Error opening file region", e);
}
}
I have save the data into the database via hibernate-mapping as binary
<hibernate-mapping>
<class name="com.admin.AuthorityApprovalForms"
table="AUTHORITY_APPROVAL_FORMS">
<id name="id" type="long">
<generator class="native"/>
</id>
<many-to-one name="OfferId" class="com.admin.core.Offer">
<column name="offer_id"/>
</many-to-one>
<property name="name" type="string"/>
<property name="type" type="string"/>
<property name="img" type="binary"/>
</class>
</hibernate-mapping>
in JSP
<img src="trasnferImage.html?formId=<%= String.valueOf(formId) %>"
align="absmiddle" border="0">
However, when jpg is displaying, it appear to be corrupted, with green and
black back ground (similar to missing layers).
I Think this is something to do with setting up the content type? can some
one help me with how to set it up?
I even check byte compression between before and after saving the data, and
no different between that either, can some one please help regards that or
give me some comments regards the problem.
I even upgrade the database version,
All I want to do is, upload the jpg files to the database then later display
it.
Regards
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: dilan@waterfind.com.au
Subject: Re: Dynamically Out put a image in Jsp
In-Reply-To: <200505270137.j4R1bWMh029971@internal.waterfind.com.au>
References: <42967356.2060507@fastcrypt.com> <200505270137.j4R1bWMh029971@internal.waterfind.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox