使用 Python 更新 alfresco 中的现有文件

Update a existing file in alfresco using Python

如何通过 Python

使用 CMis 更新露天中的现有文件

下面是我上传文件的方法

def alfresco_post_file(url, user, pwd, root_folder, post_folder, post_file, file_name, logger):
        client = CmisClient(url, user, pwd)
        repo = client.defaultRepository    
        try:
            folder = repo.getObjectByPath('/'+root_folder)
            if post_folder:
                folder = repo.getObjectByPath('/'+post_folder)
            contents = open(post_file, 'r')
            file = folder.createDocument(file_name, contentFile = contents)
        except Exception as e:
            sys.exc_clear()
            if type(e).__name__ == 'ObjectNotFoundException':
                folder = repo.getObjectByPath('/'+root_folder)
                createfolder = folder.createFolder(post_folder.replace(root_folder+'/',''))
                folder = repo.getObjectByPath('/'+post_folder)
                contents = open(post_file, 'r')
                file = folder.createDocument(file_name, contentFile = contents)
            #elif type(e).__name__ == 'UpdateConflictException':
                #folder = repo.getObjectByPath('/'+post_folder)
                #contents = open(post_file, 'r')
                #file = folder.updateDocument(file_name, contentFile = contents)
            else:
                print("(alfresco_post_file) Execution failed:", e)
                logger.info('(alfresco_post_file) Execution failed:' + str(e));

源代码通常是示例的良好来源。在这种情况下,我从 cmislibtest.py:

中的一个测试中抓取了几行
# check out the document to get its Private Working Copy (PWC):
pwc = newDoc.checkout()

# update the PWC with a new file
f = open(testFile2, 'rb')
pwc.setContentStream(f)
f.close()

# checkin the PWC
newDoc = pwc.checkin()