cancel
Showing results for 
Search instead for 
Did you mean: 

Create version programmatically and update binary content

leonardo_celati
Champ in-the-making
Champ in-the-making
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…‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
1 REPLY 1

s_palyukh
Star Contributor
Star Contributor
The following code should work:
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);origin.properties.content.write(version.properties.content);‍‍‍‍‍‍‍‍‍‍‍‍