我已经创建了一个JavaServlet来访问HCP存储库。我使用了sap.ui.unified.FileUploader将文件上载到上面的存储库中。这会导致以下错误:
409冲突,{“exception”:“constraint”,“message”:“缺少强制属性:cmis:name”}。
我使用以下代码使用fileuploader以表单形式提交数据:

<upload:FileUploader id="fileUploader" uplaodStart="handleUploadStart" uploadProgress="handleUploadProgress" uploadComplete="handleUploadComplete">
                    <upload:parameters>
                        <upload:FileUploaderParameter name="cmisaction" value="createDocument"></upload:FileUploaderParameter>
                        <upload:FileUploaderParameter name="propertyId[0]" value="cmis:objectTypeId"></upload:FileUploaderParameter>
                        <upload:FileUploaderParameter name="propertyValue[0]" value="cmis:document"></upload:FileUploaderParameter>
                        <upload:FileUploaderParameter name="propertyId[1]" value="cmis:name"></upload:FileUploaderParameter>
                        <upload:FileUploaderParameter name="propertyValue[1]" id="cmisname"></upload:FileUploaderParameter>
                    </upload:parameters>
                </upload:FileUploader>
                <Button text="Upload File" press="handleUploadPress"/>

控制器代码如下:
handleUploadPress: function(oEvent) {
        debugger;
        var oFileUploader = this.getView().byId("fileUploader");
        var repoid="94hjinnfsai8opwroiwlnnsa";
        var file = jQuery.sap.domById(oFileUploader.getId()+"-fu").files[0];
        this.getView().byId("cmisname").setValue(file.name);
        oFileUploader.setUploadUrl("/destinations/destinationName/json/"+repoid+"/root");
        oFileUploader.setFileType("multipart/form-data");
        oFileUploader.upload();
    }

我正在fileuploader的参数聚合中使用cmis:name参数,但有时它会工作,有时会出现上述错误。然而,文档中提供的html5表单工作得很好。所以,我使用fileuploader作为表单。html5代码如下:
<form action="/destinations/destinationName/json/c4hjinnfsai8opwroiwlnnsa/root"
    enctype="multipart/form-data" method="post">
    <p>
        Please specify a file:<br> <input type="file" id="filename"
            onchange="setFilename()" name="datafile" size="40">
    </p>
    <div>
        <input type="submit" value="Upload">
            <input name="cmisaction" type="hidden" value="createDocument"/>
            <input name="propertyId[0]" type="hidden" value="cmis:objectTypeId"/>
            <input name="propertyValue[0]" type="hidden" value="cmis:document"/>
            <input name="propertyId[1]" type="hidden" value="cmis:name"/>
            <input name="propertyValue[1]" type="hidden" id="cmisname"/>
    </div>
</form>

请帮忙。

最佳答案

尽管我回信很晚,但这可能对其他人有帮助。我可以用延迟呼叫来解决这个问题。将值设置为参数后,不要立即上载。
这是我的代码:

handleUploadPress: function(oEvent) {
        var oFileUploader = this.getView().byId("fileUploader");
        if (!oFileUploader.getValue()) {
            MessageToast.show("Choose a file first");
            return;
        }
        var cmisname = oFileUploader.getValue();
        oFileUploader.addParameter(new sap.ui.unified.FileUploaderParameter({
            name: "propertyValue[1]",
            value: cmisname
        }));
        jQuery.sap.delayedCall(100, this, function() {
            oFileUploader.upload();
        });

    }

09-25 21:41