cancel
Showing results for 
Search instead for 
Did you mean: 

Transform and add as association without adding to folder

mycroes
Champ in-the-making
Champ in-the-making
I have files that I want to offer to users as PDF. I'm able to convert the original file to PDF using a webscript. However, if I don't give a destination node, the PDF file will also get listed in the folder where the original file is. I can't use the original file as destination, because it is "cm:content" and not a container.

I want to use something similar to what the thumbnailservice does: create the converted document and associate it with the original document. Is this possible from webscripts? I don't know where the converted document should be stored, but in my opinion it doesn't need a parent at all. As long as it has a nodeRef that can be used to download it I can use it.
Regards,

Michael
2 REPLIES 2

lista
Star Contributor
Star Contributor
Hi,

are you trying to avoid adding to folder completely? Because you could use the original content's parent for the converted content, too.
This is no trouble to do, and this way you'd have both contents in the same space.

A bit about associations.

Cheers,
Lista

mycroes
Champ in-the-making
Champ in-the-making
Thanks for your reply Lista.

are you trying to avoid adding to folder completely? Because you could use the original content's parent for the converted content, too.
I don't want to add it to any folder because I don't want it to be available as a seperate document. I don't want people to version the transform, remove it, edit it or anything like that, I only want to offer it as a download by using a custom library action.

I have currently implemented this action by transforming without a second argument for the transform function, which causes the file to appear in the same folder as the original document. I also add an association (currently using the cm:transformable/cm:formats association), but I don't want the file to ever be inside the folder.

My current webscript is this:
   var results = [];

   var files = p_params.files;

   var file, result, nodeRef;



   for (file in files)

   {
      nodeRef = files[file];
      result =
      {
         action: "downloadPdf",
         nodeRef: nodeRef,
         success: false
      }
         



      file = search.findNode(nodeRef);

      var pdfFile = file.transformDocument("application/pdf");
      if (!file.hasAspect("cm:transformable")) {
         file.addAspect("cm:transformable");
      }
      file.createAssociation(pdfFile, "cm:formats");

      result.id = pdfFile.name;
      result.nodeRef = pdfFile.nodeRef.toString();
      result.success = true;


      results.push(result);

   }



   return results;

I then use client side javascript to redirect to the newly created document.

I already looked at the associations page, but I don't see how I could use it to directly attach the transformation to the original document (remember I have to specify a parent as second argument for the transformDocument call if I want to do that).
Regards,

Michael