cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS: save files with the same name

viktoriyamoskov
Champ on-the-rise
Champ on-the-rise

Good day.

I create a document in Alfresco using CMIS. Code:

Session session = ...

Folder parent = session.getRootFolder ();

String textFileName = "test.txt"; // prepare content - a simple text file

String content = "Hello World!";

String filename = textFileName;

String mimetype = "text / plain; charset = UTF-8";

byte [] contentBytes = content.getBytes ("UTF-8");

ByteArrayInputStream stream = new ByteArrayInputStream (contentBytes);

ContentStream contentStream = session.getObjectFactory (). CreateContentStream (filename, contentBytes.length, mimetype, stream); // prepare properties

Map <String, Object> properties = new HashMap <String, Object> ();

properties.put (PropertyIds.NAME, textFileName);

properties.put (PropertyIds.OBJECT_TYPE_ID, "cmis: document"); // create the document

Document newDoc = parent.createDocument (properties, contentStream, VersioningState.MAJOR);

However, when I save a file with the same name twice, I get a CmisContentAlreadyExistsException.
When I add files with the same name through Alfresco, suffixes are added to the file names (as file_name-1, file_name-2 ...). Is it possible to save files with the same name via CMIS?

Thanks!

4 REPLIES 4

binduwavell
Star Contributor
Star Contributor

My recollection is that the renaming is done by the UI by catching the exception, and updating the name until that exception is not thrown.

Thanks for your reply.
As I understand it, CMIS does not contain functionality for renaming files with the same name?

Right, if you want renaming, you have to implement it in your code that is using CMIS.

Thank you for help.