cancel
Showing results for 
Search instead for 
Did you mean: 

Java-backed webscript to return a file (comes in byte[] format)

sunquanbin
Champ on-the-rise
Champ on-the-rise
Hi Everyone,

My scenario is that I have a Java-backed webscript which interacts with third-party library and as a result, a file is returned (in byte[] type).
My question is how can I convert this byte[] into a file and pass it back in the webscript response (I only knew how to create a JSON response)?

The solution I could think of was to
1.create a node in alfresco and put that byte[] as its content.
2.get the download url for the created node content
3.put this url in the JSON response.

I am sure there must be a more simpler solution to my existing one as I'm new to Alfresco.

Can anyone help?

Many thanks

Sun

2 REPLIES 2

mrogers
Star Contributor
Star Contributor
Yes you could do that.  

Or you could write your content to the webscript response, either in binary or appropriately encoded.  

Do you want JSON as the result of your webscript or the byte[] stream?

Hi,

I'm now using the webscript provide by default. I put the following url in an html <a> tag:

Host/api/node/content/workspace/SpacesStore/{nodeRef}/filename.ext?a=true, and the user can download the file by click the link.

I'm extends the "AbscractWebscript" class to handle the webscript and it can only write JSON response (or I only know this way).

Would you please provide more information of how I can do it via the approaches you mentioned?

Thanks in advance,

Sun