Sapui5 在Javascript中使用CMIS创建文档

Sapui5 在Javascript中使用CMIS创建文档,sapui5,cmis,opencmis,Sapui5,Cmis,Opencmis,我正在尝试使用Javascript在HCP的SAP文档中心创建一个文档,但我无法。SAP Document Center使用CMIS协议与其他应用程序进行通信。我已经能够从我的SAPUI5应用程序连接到SAP文档中心。我还创建了一个文件夹,如下所示: createFolder: function(repositoryId, parentFolderId, folderName) { var data = { objectId: parentFolderId

我正在尝试使用Javascript在HCP的SAP文档中心创建一个文档,但我无法。SAP Document Center使用CMIS协议与其他应用程序进行通信。我已经能够从我的SAPUI5应用程序连接到SAP文档中心。我还创建了一个文件夹,如下所示:

createFolder: function(repositoryId, parentFolderId, folderName) {
        var data = {
            objectId: parentFolderId,
            cmisaction: "createFolder",
            "propertyId[0]": "cmis:name",
            "propertyValue[0]": folderName,
            "propertyId[1]": "cmis:objectTypeId",
            "propertyValue[1]": "cmis:folder"
        };

        $.ajax("/destination/document/mcm/json/" + repositoryId + "/root", {
            type: "POST",
            data: data
        }).done(function() {
            MessageBox.show("Folder with name " + folderName + " successfully created.");
        }).fail(function(jqXHR) {
            MessageBox.show("Creation of folder with name " + folderName + " failed. XHR response message: " + jqXHR.responseJSON.message);
        });
    },
createDocument: function(repositoryId, parentFolderId, documentName, content) {
            /** 
             * 'content' contains the whole document converted to a base64 string like this:
             * "data:application/pdf;base64,JVBERi0xLjUNJeLjz9MNCjIxNCAwIG9iag08P..."
             */
            var data = {
                objectId: parentFolderId,
                cmisaction: "createDocument",
                contentStream: content,
                "propertyId[0]": "cmis:name",
                "propertyValue[0]": documentName,
                "propertyId[1]": "cmis:objectTypeId",
                "propertyValue[1]": "cmis:document"
            };

            $.ajax("/destination/document/mcm/json/" + repositoryId + "/root", {
                type: "POST",
                data: data
            }).done(function() {
                MessageBox.show("Document with name " + documentName + " successfully created.");
            }).fail(function(jqXHR) {
                MessageBox.show("Creation of document with name " + documentName + " failed. XHR response message: " + jqXHR.responseJSON.message);
            });
        },
但是,我发现创建文档是不可能的。我找不到CMIS“createDocument”方法的internet示例。Java有很多例子,但与Javascript无关。我不知道要发送的数据结构是什么。代码如下:

createFolder: function(repositoryId, parentFolderId, folderName) {
        var data = {
            objectId: parentFolderId,
            cmisaction: "createFolder",
            "propertyId[0]": "cmis:name",
            "propertyValue[0]": folderName,
            "propertyId[1]": "cmis:objectTypeId",
            "propertyValue[1]": "cmis:folder"
        };

        $.ajax("/destination/document/mcm/json/" + repositoryId + "/root", {
            type: "POST",
            data: data
        }).done(function() {
            MessageBox.show("Folder with name " + folderName + " successfully created.");
        }).fail(function(jqXHR) {
            MessageBox.show("Creation of folder with name " + folderName + " failed. XHR response message: " + jqXHR.responseJSON.message);
        });
    },
createDocument: function(repositoryId, parentFolderId, documentName, content) {
            /** 
             * 'content' contains the whole document converted to a base64 string like this:
             * "data:application/pdf;base64,JVBERi0xLjUNJeLjz9MNCjIxNCAwIG9iag08P..."
             */
            var data = {
                objectId: parentFolderId,
                cmisaction: "createDocument",
                contentStream: content,
                "propertyId[0]": "cmis:name",
                "propertyValue[0]": documentName,
                "propertyId[1]": "cmis:objectTypeId",
                "propertyValue[1]": "cmis:document"
            };

            $.ajax("/destination/document/mcm/json/" + repositoryId + "/root", {
                type: "POST",
                data: data
            }).done(function() {
                MessageBox.show("Document with name " + documentName + " successfully created.");
            }).fail(function(jqXHR) {
                MessageBox.show("Creation of document with name " + documentName + " failed. XHR response message: " + jqXHR.responseJSON.message);
            });
        },
通过此操作,我在SAP Document Center中创建了一个文件记录,但它不接受数据。当应发送格式(PDF、txt、Excel、Doc等)时,将创建未格式化文件

有人知道怎么做吗

问候

感兴趣的链接:

CMIS标准

Java(非Javascript)的使用示例
我也遇到过类似的问题。我的解决方案是将其从base64更改为FormData方法,因此我得到的是文件输入值,而不是内容base64字符串。它工作得很好

 this.createObject = function (fileInput, objectName,folderId, cbOk, cbError) {

        if (!folderId) {
            folderId = _this.metadata.rootFolderId;
        }

        var documentData = {
            'propertyId[1]': 'cmis:objectTypeId',
            'propertyValue[1]': 'cmis:document',
            'propertyId[0]': 'cmis:name',
            'propertyValue[0]': objectName,
            'objectId': folderId,
            'cmisaction': 'createDocument',
            'content' : fileInput
        };

        var formData = new FormData();

        jQuery.each(documentData, function(key, value){
            formData.append(key, value);
        });


        $.ajax({
            url: _this.metadata.actionsUrl,
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function(data){
                cbOk(data);
            },
            error: function(err){
                cbError(err);
            }
        });
    };

在view.xml中添加以下行

<FileUploader id="fileUploader" 
              name="myFileUpload" 
              uploadUrl="/cmis/root"
              width="400px" 
              tooltip="Upload your file to the local server" 
              uploadComplete="handleUploadComplete" 
              change='onChangeDoc'/>
{
    "path": "/cmis",
    "target": {
        "type": "destination",
        "name": "documentservice"
    },
    "description": "documentservice"
}
在controller.js中添加以下代码行

if (!oFileUploader.getValue()) {
    sap.m.MessageToast.show("Choose a file first");
    return;
}

var data = {
    'propertyId[0]': 'cmis:objectTypeId',
    'propertyValue[0]': 'cmis:document',
    'propertyId[1]': 'cmis:name',
    'propertyValue[1]': file.name,
    'cmisaction': 'createDocument'
};

var formData = new FormData();
formData.append('datafile', new Blob([file]));
jQuery.each(data, function(key, value) {
    formData.append(key, value);
});

$.ajax('/cmis/root', {
    type: 'POST',
    data: formData,
    cache: false,
    processData: false,
    contentType: false,
    success: function(response) {
        sap.m.MessageToast.show("File Uploaded Successfully");              
    }.bind(this),
    error: function(error) {
        sap.m.MessageBox.error("File Uploaded Unsuccessfully. Save is not possible. " + error.responseJSON.message);
    }
});
在neo cloud中,在destination选项卡中维护以下配置的url<代码>https://testdaasi328160trial.hanatrial.ondemand.com/TestDaaS/cmis/json/repo-id

repo id将是您的存储库密钥


这将解决问题。您将能够上载和保存文档。

您是否尝试将内容类型设置为“多部分/表单数据”?