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

2024-09-26 18:09:04 发布

您现在位置:Python中文网/ 问答频道 /正文

如何通过Python使用CMis更新alfresco中的现有文件

下面是我用来上传文件的方法

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));

Tags: 文件nameurlpwdcontentsreporootopen
1条回答
网友
1楼 · 发布于 2024-09-26 18:09:04

源代码通常是很好的示例源代码。在本例中,我从中的一个测试中获取了几行代码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()

相关问题 更多 >

    热门问题