2

我创建了一个 Java Servlet 来访问 HCP 存储库。我已经使用 sap.ui.unified.FileUploader 将文件上传到上述存储库。它给了我以下错误:409 Conflict, {"exception":"constraint","message":"Mandatory property missing: 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>

请帮忙。

4

1 回答 1

0

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

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

    }
于 2018-03-09T23:00:42.947 回答