users@glassfish.java.net

Re: File transfer from client -> server

From: Wolfram Rittmeyer <w.rittmeyer_at_jsptutorial.org>
Date: Wed, 22 Apr 2009 18:23:02 +0200

Morten O. Hansen wrote:
>
> Hi
>
> What would be the best way to transfer files from the client to the
> server? I have looked at using JMS, and while this works.. it seems to
> break what JMS is supposed to be used for. The files are between 100kb
> and 10mb, but the system should be able to handle 1gb files if necessary.

I think this depends on the client. Sending byte arrays via RMI probably
is very efficient - but firewalls might not allow to do this. Http
Upload (actually you can simply put the payload into the body of a POST
request) might be a solution for external clients. I do know that we use
Queues at work, but since I was not involved in this part of the
project, I cannot tell much about it - probably proprietary extensions
were used.

> The file would be put into a database on the server side, and ideally it
> should be able to stream the file into a blob (but it doesnt seem that
> java.sql.Blob is supported by JPA?).

You can use @Lob which is translated into corresponding types of the
database. But this of course is not very flexible (no possibility to set
or get readers or streams) - so my guess is that the performance is far
from optimal for large files like those you mentioned. I currently
wonder about the same problem (that is using CLOBS efficiently with JPA) ;-)

> Any hints on where to look would be appreciated, even just a
> confirmation that JMS is the way to go here. The server should also
> report back how much data is received, but that part is surely fitted
> for JMS.
>
> Thanks!
> Morten
>