cancel
Showing results for 
Search instead for 
Did you mean: 

update the contents with another contents

frama
Champ in-the-making
Champ in-the-making
Hello, let me know if you can do this through Web Services.
I would like to update the contents of a file in Alfresco, with the contents
of another file also different in Alfresco, but I do not want to transfer the
contents through my application.

It would be something like:


   Reference theReference = getReferencia(uuid, null);
   Predicate predicate = new Predicate(new Reference[] { theReference }, spacesStore, null);
   Content [] content = contentService.read (predicate, Constants.PROP_CONTENT);
   contentService.write(referenceNode, Constants.PROP_CONTENT, content[0]);


Thanks
3 REPLIES 3

jos_snellings
Champ in-the-making
Champ in-the-making
Yes you can. In the code you posted you are reading the content from another node. Here is an example with as the input
for the update an on-disk file. Meta-data in the original remain untouched.

    Reference contentReference = getReferencia(uuid, null);

    // read file into byte array
    InputStream is = new FileInputStream(file);

    // Get the size of the file
    long length = file.length();
    if (length > Integer.MAX_VALUE) {
      return false;
    }

    byte[] bytes = new byte[(int) length];

    // Read in the bytes
    int offset = 0;
    int numRead = 0;
    while (offset < bytes.length
        && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
      offset += numRead;
    }

    // Ensure all the bytes have been read in
    if (offset < bytes.length) {
      throw new IOException("Could not completely read file " + file.getName());
    }

    // Close the input stream and return bytes
    is.close();

    ContentFormat cf = new ContentFormat(<themimetype>, <theencoding>);

    contentService.write(contentReference, Constants.PROP_CONTENT, bytes, cf);

frama
Champ in-the-making
Champ in-the-making
Thank you for your reply.

That's what I'm doing now. The problem is that communication between my application and Alfresco is slow and that means downloading and then upload again. What we do is pass it may require a node to another without passing the inputstram for my application.

Thank you.

jos_snellings
Champ in-the-making
Champ in-the-making
I see your point.  There is no 'copyNode' method that i can see now. Sorry.