cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Downloading File From Alfresco

mbarrerag
Champ in-the-making
Champ in-the-making
Hi everyone,

I know that there is a lot of information on the web about how to download a file using the webservice client, but i couldn't find anything about my problem.

The problem is that i can download a file from the alfresco's repo but the file is always incomplete, i really dont know how to change this. Here's my code:

   public static Content download(String name, Reference folder,
         AuthenticationDetails session) throws NodeAlfrescoException {
      Content content = null;
      try {
         AuthenticationUtils.setAuthenticationDetails(session);
         String alfrescoRoot = Utils.appProperties().getProperty("alfresco.url");
         alfrescoRoot += "api";
         WebServiceFactory.setEndpointAddress(alfrescoRoot);
         Reference ref = new Reference(STORE, null, folder.getPath()
               + "/cm:" + name);
         Content[] read = getContentService().read(
               new Predicate(new Reference[]{ref}, STORE, null),
               Constants.PROP_CONTENT);
         content = read[0];
      } catch (Exception e) {
         e.printStackTrace();
         throw new NodeAlfrescoException();
      }
      return content;
}
Please any help
Thanks in Advance!!
1 REPLY 1

mbarrerag
Champ in-the-making
Champ in-the-making
Here is a fix of the same method and it is solved:


   public static OutputStream download(String name, Reference folder,
         AuthenticationDetails session, boolean f) throws IOException {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      AuthenticationUtils.setAuthenticationDetails(session);
      String alfrescoRoot = Utils.appProperties().getProperty(
            "alfresco.url");
      alfrescoRoot += "api";
      WebServiceFactory.setEndpointAddress(alfrescoRoot);
      WebServiceFactory.setTimeoutMilliseconds(120000);
      Reference ref = new Reference(STORE, null, folder.getPath()
            + "/cm:" + name);
      Content[] read = getContentService().read(
            new Predicate(new Reference[] { ref }, STORE, null),
            Constants.PROP_CONTENT);
      Content content = read[0];
      ContentUtils.copy(ContentUtils.getContentAsInputStream(content), out);
      return out;
   }

Using an OutputStream seems to fix the problem

Hope this help to anyone.

Best Regards