2

I have created a Java Servlet to access the HCP repository. I have used sap.ui.unified.FileUploader to upload a file to the above repository.It gives me following error: 409 Conflict, {"exception":"constraint","message":"Mandatory property missing: cmis:name"}.

I have used following code to submit data as a form using 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"/>

and the code in controller is as follows:

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

I am using the cmis:name parameter in the parameters aggregation of fileuploader but sometimes it works and sometimes it gives the above error. However, html5 form provided in the documentation works perfectly. So, I have used fileuploader to act as a form. The html5 code is as below:

<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>

Please help.

abhhab
  • 253
  • 2
  • 6
  • 22

1 Answers1

0

Even though I am replying quite late but it might be helpful for others. I am able to solve this issue using delayed call. After setting the value to parameter, do not upload immediately. Here is my code:

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

    }