AnsweredAssumed Answered

Create version programmatically and update binary content

Question asked by leonardo.celati on Dec 7, 2014
Latest reply on Jan 16, 2015 by s.palyukh
Instead of uploading new version via alfresco share interface, a group of files have been mistakenly uploaded by the graphic department straight into an alfresco folder.
Therefore the only option I have, is to download each file, and load them one by one into the proper version.

It would be great if this could be done via Javascript API. I see there a specific version api, but I couldn't find a way to upload the content of the file.
This is what I have tried, but it results in the file being corrupted. I hope I made myself clear about what I am trying to achieve.


// the original file to be versioned (jpg)
var originId = "workspace://SpacesStore/08244ba1-a795-4751-9052-cd236a532820";
// the file uploaded by the graphic department (jpg)
var versionId = "workspace://SpacesStore/a6b0f218-9d3a-4fe3-be1f-1a1cd192212d";

var origin = search.findNode(originId);
var version = search.findNode(versionId);

var newVersion = origin.createVersion("new version",false);
var newFile = search.findNode(newVersion.nodeRef);
newFile.content= version.content;

// if succeed delete versionId…

Outcomes