在Javascript

时间:2017-06-13 08:32:02

标签: sapui5 cmis opencmis

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

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

但是,我发现无法创建文档。我找不到CMIS“createDocument”方法的互联网示例。 Java有很多例子,但与Javascript无关。我不知道要发送的数据结构是什么。代码如下:

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标准 http://docs.oasis-open.org/cmis/CMIS/v1.1/os/CMIS-v1.1-os.html#x1-1710002

Java的使用示例(不是Javascript) http://chemistry.apache.org/java/developing/guide.html

2 个答案:

答案 0 :(得分:1)

我遇到了类似的问题。我的解决方案是将它从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);
            }
        });
    };

答案 1 :(得分:0)

在view.xml中添加以下行。

<FileUploader id="fileUploader" 
              name="myFileUpload" 
              uploadUrl="/cmis/root"
              width="400px" 
              tooltip="Upload your file to the local server" 
              uploadComplete="handleUploadComplete" 
              change='onChangeDoc'/>

上传网址将是neo目的地的网址。在 neo.app.json 中添加以下行。

{
    "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中,维护目标选项卡中的以下配置的URL。 https://testdaasi328160trial.hanatrial.ondemand.com/TestDaaS/cmis/json/repo-id

repo-id将是您的存储库密钥。

这将解决问题。您将能够上传文档。