Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to return big chunks of binary data from a webservice?

I am implementing a webservice that returns the content of binary files. The files are about 100MB big. The webservice and the client are build upon Axis2.

What is the best joice for the return type of the method that returns the data?

I tried byte[], but I always get OutOfMemoryErrors on the server side. Plus I am not very happy to have the whole file content in memory. Is there something stream-alike that I can use instead?

like image 724
ftl Avatar asked Oct 01 '09 12:10

ftl


2 Answers

Instead of returning the data, can you return a temporary URL pointing to this big result saved as a temporary file ? Or can you return your file as a series of smaller results ?

like image 197
Pierre Avatar answered Oct 21 '22 19:10

Pierre


The article "Downloading a Binary File from a Web Service using Axis2 and SOAP with Attachments" describes exactly the solution I was looking for. Big chunks of data are added as attachment to the SOAP response of the webservice using "SOAP with Attachments" (SwA).

I can use a javax.activation.DataSource which provides an InputStream and I do not have to hold the whole file in memory.

like image 34
ftl Avatar answered Oct 21 '22 19:10

ftl