Foren

Store files into Database (oracle) within portlet

Mathias Lehmann, geändert vor 12 Jahren.

Store files into Database (oracle) within portlet

New Member Beiträge: 19 Beitrittsdatum: 02.03.11 Neueste Beiträge
Hello @all,
i have to develop a portlet such as documentlibrary. The Portlet uploads Files with specific attributes entered by the user.
User can search for documents by those attributes and download them.

I plan to have two tables.

One Table with Doc_ID and Document as blob (Oracle datatype).
A second table with Doc_ID and a lot of columns (attributes).

I can use ServiceBuilder for my finderMethods. But how can i load the file into database?
The Documentlibrary uses Jackrabbit. Can i also use jackrabbit or should i use custom sql ?

Are there any examples of how to store files into DB?
I looked at MessageBoard portlet (attachments) and Documentlibrary. But i can't find where the files persist into DB?
Can anyone help me?
Thanks in advance!

Best regards
Mathias
thumbnail
David H Nebinger, geändert vor 12 Jahren.

RE: Store files into Database (oracle) within portlet

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
Storing a file is not much different than storing a string or a numerical value, although you'll need to figure out how you want to implement it.

For the most part, you're going to be passing an object stream when you are inserting the row. The object stream represents the file data. If you're holding the data in memory, you can use the ByteArrayOutputStream from the data to stream it. If the file is on the filesystem, you can just use a FileOutputStream.

The fun part in the portlet world is the actual upload of a file. In our environment, we use a servlet for the file uploads. The servlet receives the file and the 'attributes' and will store the file in the database or on the filesystem, depending upon requirements. The fronting portlet just provides the form and framework for initiating the upload through the servlet itself.
Mathias Lehmann, geändert vor 12 Jahren.

RE: Store files into Database (oracle) within portlet

New Member Beiträge: 19 Beitrittsdatum: 02.03.11 Neueste Beiträge
Hello David,
thanks a ton for the reply. It sounds good. Maybe i should also use a servlet and form.
How do i get the Database source (Database schema of portal and Table to store the file). Do i have to use liferay packages? Or should i use service Builder and / or custom sql?

Thanks!

Best regards,
Mathias
thumbnail
David H Nebinger, geändert vor 12 Jahren.

RE: Store files into Database (oracle) within portlet

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
You can go either way. If your servlet is part of the same WAR that your portlet is in and you've got spring configured correctly, the servlet will have the same access to resources that the portlet would have, thus allowing for the use of service builder.
Mathias Lehmann, geändert vor 12 Jahren.

RE: Store files into Database (oracle) within portlet

New Member Beiträge: 19 Beitrittsdatum: 02.03.11 Neueste Beiträge
Thanks. I will try it emoticon