AnsweredAssumed Answered

subir pdf con web services

Question asked by jamoreno on Feb 7, 2008
Hola a todos. Estoy intentando subir un pdf a Alfresco utilizando WebService. Tiene el mismo tamaño y las mismas páginas que el original, pero al abrirlo me aparecen todas las páginas en blanco. 

El código es el siguiente:

// Start the session
       AuthenticationUtils.startSession("admin", "admin");
           // Create a reference to the parent where we want to create content
            Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
            ParentReference companyHomeParent = new ParentReference(storeRef, null, "/app:company_home", Constants.ASSOC_CONTAINS, null);

            // Assign name
            String name = "Web Services sample.pdf";
            companyHomeParent.setChildName("cm:" + name);
            // Construct CML statement to create content node
            // Note: Assign "1" as a local id, so we can refer to it in subsequent
            //       CML statements within the same CML block
            NamedValue[] contentProps = new NamedValue[1];
            contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, name);
            CMLCreate create = new CMLCreate("1", companyHomeParent, null, null, null, Constants.TYPE_CONTENT, contentProps);
            // Construct CML statement to add titled aspect
            NamedValue[] titledProps = new NamedValue[2];
            titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, name);
            titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, name);
            CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
            // Construct CML Block
            CML cml = new CML();
            cml.setCreate(new CMLCreate[] {create});
            cml.setAddAspect(new CMLAddAspect[] {addAspect});

            UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);    
            Reference content = result[0].getDestination();
         // Open the file and convert to byte array
            URL url = new URL(("http://localhost/Alfresco-Tutorial.pdf"));
            InputStream viewStream = url.openStream ();
            BufferedReader dis = new BufferedReader (new InputStreamReader (viewStream));
            String line = "";
            StringBuffer fBuf   = new StringBuffer();
            while ( (line = dis.readLine ()) != null) {
                fBuf.append (line + "\n");
            byte[] bytes = ContentUtils.convertToByteArray(viewStream);
            ContentFormat format = new ContentFormat("application/pdf", "UTF-8");
//             Write the content
            WebServiceFactory.getContentService().write(content, Constants.PROP_CONTENT, fBuf.substring(0).getBytes(), format);
        catch(Throwable e)
            // End the session

Muchas gracias a todos.