cancel
Showing results for 
Search instead for 
Did you mean: 

Download content by uuid with streaming

spilby
Confirmed Champ
Confirmed Champ
I want to download content from alfresco by the uuid of the node. This content may be a big file, bigger than 500MB.

What's the best way to download large contents with streaming? Using the DownloadContentServlet? Or implementing a java backed webscript doing something like this:


ContentReader contentReader = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
InputStream is = contentReader.getContentInputStream();
BufferedReader br= new BufferedReader(new InputStreamReader (is));


Or is more efficient another way? What's your opinion? May be a lot of users downloading contents, is the reason I want something with streaming, to not crash down the server with simultaneous downloads.

And if I use the DownloadContentServlet, how can I call it? This is the url I found to use it:


/alfresco/download/<direct|attach>/<workspace>/<store>/<nodeId>/<filename>


I must do a HttpClient call on a servlet to this url to download it? Is the same url than if I do this?


Content[] content = WebServiceFactory.getContentService().read(new Predicate(new Reference[]{fileRef}, STORE, null) , "{http://www.alfresco.org/model/content/1.0}content" );
String url = content[0].getUrl();


Or what's the difference? I don't understand these different ways…

Thank you very much!
12 REPLIES 12

spilby
Confirmed Champ
Confirmed Champ
Oks!  Thank you very much!

Two things only about the code…

1. What is inputStream? I supose that each entity call add on inputStream empty variable the block that I read on each HttpPut. But how must I define it before? Doing this for example is ok?:


ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[] {});


Then to the response of the Servlet, I do something like this:


OutputStream os = response.getOutputStream();     
try{
   byte[] buffer = new byte[4096];
   int numRead;
   while( ( numRead = inputStream.read( buffer ) ) != -1 ){
      os.write( buffer, 0, numRead );
   }
}finally{
   try{ inputStream.close(); }catch ( Exception ex ){}
}


I imagine that doing this my servlet not have in memory all the alfresco file, and the streaming works. You see it ok?

2. And for curiosity. If I obtain the content from alfresco, why HttpPut instead of HttpGet?

Thanks again!

kaynezhang
World-Class Innovator
World-Class Innovator
You can use http get,I have already updated the sample code according apache common httpclient 3.x.
It is still an example ,you should modify it according you requirment,for example using multi threads.
I'm sorry for my mistake.

Thanks a lot! The code is perfect for me. I understand perfectly what I need and I'm sure it can help a lot of people. Thanks again!