I have a requirement to create a smart service, which writes a file from My Sys

I have a requirement to create a smart service, which writes a file from My System Folder (Source) to Appain Knowledge center (Destination).

How to create a "versioning" on a file in knowledge center (Destination) when I try to write a duplicate file from Source location ?
How to check if source file is duplicate (already exists) in knowledge center based on this it creates a versions to the file in Knowledge center ?

I have a trouble in doing this in smart service code.
Can anyone suggest how to achieve it .

I have only this right now:
Write the file of ByteArrayOutputStream to ContentOutputStream

Document doc = new Document();
                    doc.setParent(destinationfolderId);
                    doc.setName(fileName);
                    doc.setExtension("pdf");
                    ContentOutputStream cos = contentService.upload(doc, Content.UNIQUE_NONE);
                    cos.write(boStrm.toByteArray());
...

OriginalPostID-131853

OriginalPostID-131853

  Discussion posts and replies are publicly visible