Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Mathias Lehmann
Store files into Database (oracle) within portlet
15 de Julho de 2011 06:01
Resposta

Mathias Lehmann

Ranking: New Member

Mensagens: 19

Data de entrada: 2 de Março de 2011

Mensagens recentes

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
David H Nebinger
RE: Store files into Database (oracle) within portlet
15 de Julho de 2011 06:20
Resposta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensagens: 11046

Data de entrada: 1 de Setembro de 2006

Mensagens recentes

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
RE: Store files into Database (oracle) within portlet
18 de Julho de 2011 07:11
Resposta

Mathias Lehmann

Ranking: New Member

Mensagens: 19

Data de entrada: 2 de Março de 2011

Mensagens recentes

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
David H Nebinger
RE: Store files into Database (oracle) within portlet
18 de Julho de 2011 07:16
Resposta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensagens: 11046

Data de entrada: 1 de Setembro de 2006

Mensagens recentes

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
RE: Store files into Database (oracle) within portlet
18 de Julho de 2011 23:35
Resposta

Mathias Lehmann

Ranking: New Member

Mensagens: 19

Data de entrada: 2 de Março de 2011

Mensagens recentes

Thanks. I will try it emoticon