Uploading documents to Alfresco CMIS using Python

302 views Asked by At

I am trying to upload documents to a Alfresco CMIS site using Python code

from cmislib.model import CmisClient

file_to_upload = open(file_full_path, 'r')

doc_in_Alfresco = archive_folder_2.createDocument(file_name, \
                                                  contentFile=file_to_upload)

Have taken the example from this help document - https://chemistry.apache.org/python/docs/examples.html

i have .txt, .rtf, . pdf, .docx documents etc.

Except for txt documents, rest of the upload is failing and the common error is LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs

The error will differ in codec name depending on the file extension.

With limited documentation help, can someone hint what can be the possible solution. I am using cmislib in Python 3 in MacOS and the code in run in Jupyter Notebook.

Any hints will be highly appreciated.

Thanks

1

There are 1 answers

0
John On

It worked for me with the following changes in place

            file_to_upload.read()
            file_data = base64.b64encode(content_file.read())
            doc_in_Alfresco = archive_folder_2.createDocument(file_name, \
                                              contentFile=file_to_upload)