使用Python在露天更新现有文件



如何使用 CMis 通过 Python 更新 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));

源代码通常是示例的良好来源。在这种情况下,我从 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()

相关内容

  • 没有找到相关文章

最新更新