cancel
Showing results for 
Search instead for 
Did you mean: 

Descargar fichero desde alfresco

sanxesito
Champ in-the-making
Champ in-the-making
Hola!
Soy nuevo en el foro, aunque ya llevo varias semanas siguiendolo

Me ha surgido una duda, y llevo varios dias intentandolo solucionar
Estoy realizando un programa en JAVA y webservices que comunica con alfresco
Realice la subida de ficheros, pero ahora estoy intentando la bajada de ficheros a mi local.


public Fichero obtenerDocumentoGD(String dir, Fichero fichero) throws Exception
{
   if (fichero.getNombreFichero()==null){
      return null;
   }
   Fichero respuesta = new Fichero();
   File f1 = null;
   String nombreFichero=fichero.getNombreFichero().toLowerCase();
   WebServiceFactory.setEndpointAddress(URL);
   WebServiceFactory.setTimeoutMilliseconds(TIMEOUT);
                AuthenticationUtils.startSession(USERNAME,PASSWORD);
                ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
                String space = PATH + "/*[@cm:name=\""+ dir + "\"]" + "/*[@cm:name=\""+nombreFichero+"\"]";
   Reference i=new Reference(STORE,null,space);
   try {
      
      Node[] nodes;
      nodes = WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[] {i}, STORE, null));
   
      if (nodes != null && nodes.length > 0) {
         Content[] readResult = WebServiceFactory.getContentService().read(new Predicate(new Reference[] {nodes[0].getReference()}, STORE, null), Constants.PROP_CONTENT);
         Content content = readResult[0];
      
          ContentUtils.copyContentToFile(content, new File("C:/docs/temp/ejemplo.txt"));

         // Definir la ruta donde se recuperará el fichero
         
         f1 = new File("C:/docs/temp/" + fichero.getNombreFichero());
         FileInputStream fis = new FileInputStream(f1);
         byte[] entryBytes = null;
         
         // Recuperar el fichero definido.
         ByteArrayOutputStream bos = new ByteArrayOutputStream();

         byte[] buffer = new byte[1024];
         int len;

         while ((len = fis.read(buffer, 0, 1024)) > -1) {
            bos.write(buffer, 0, len);
         }
         bos.flush();
         fis.close();

         entryBytes = bos.toByteArray();
         pasar(entryBytes);
         // logger.info("El fichero no se ha recuperado correctamente el
         // fichero de la ruta especificada.");
         
         respuesta.setCodigoFichero(fichero.getCodigoFichero());
         respuesta.setFichero(entryBytes);
         respuesta.setNombreFichero(fichero.getNombreFichero());
         respuesta.setRutaFichero("C:/docs/temp");
         
         
      } else {
      }
   } catch (Exception e)
   {
      e.printStackTrace();
      return null;   
   }
   finally
   {
           AuthenticationUtils.endSession();
           if (f1!=null){
           }
   }
    return respuesta;   
}

PATH es   "/app:company_home/*[@cm:name=\"" + "myFolder" + "\"]"

STORE es Store(Constants.WORKSPACE_STORE, "SpacesStore");


Siempre me da una excepcion en ….     ContentUtils.copyContentToFile(content, new File("C:/docs/temp/ejemplo.txt"));

diciendo …."Unable to get content as inputStream."

Gracias de antemano y gran foro!
10 REPLIES 10

sandrapascual
Champ in-the-making
Champ in-the-making
Hola,
Tengo un problema al recuperar los bytes[] de un objeto Content.

Utilizo el siguiente código:

byte[] result = ContentUtils.convertToByteArray(ContentUtils.getContentAsInputStream(content));

y la longitud de bytes que me devuelve es menor que la del fichero original

¿Alguna idea?