how to upload a file using file uploader for cmis workbench using file uploader?

943 Views Asked by At

I am using file uploader to upload the document using cmis connection. I have created a destination in neo trial account.

Also i am making an ajax call to upload the rest of data to the document as a service.

view.xml

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

controller.js

        var BASE64_MARKER = 'data:' + file.type + ';base64,';

        var reader = new FileReader();

        reader.onload = (function(theFile) {

            return function(evt) {

                var base64Index = evt.target.result.indexOf(BASE64_MARKER) + BASE64_MARKER.length;

                var base64 = evt.target.result.substring(base64Index);
        var data = {
            'propertyId[0]': 'cmis:objectTypeId',
            'propertyValue[0]': 'cmis:document',
            'propertyId[1]': 'cmis:name',
            'propertyValue[1]': file.name,
            'cmisaction': 'createDocument',
            'documentInputStream': base64
        };
        var formData = new FormData();

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

        $.ajax({
            type: 'POST',
            url: '/cmis/4f1abc71a1788bc6c05f54a5/root',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            success: function(response) {
                sap.m.MessageToast.show("File Uploaded Successfully");
            },
            error: function(error) {
                sap.m.MessageToast.show("File Uploaded Unsuccessfully");
            }
        });

            };

        })(file);

        reader.readAsDataURL(file);

The document is uploaded but the content is not being uploaded.

Error:

{ exception: "constraint", message: "No content available: objectid = px7goMt94zMxekyiUqQQBPWQd63-TYivo90adO1Eyxk repositoryid = 4f1abc71a1788bc6c05f54a5" }

Can anyone please help me here?

1

There are 1 best solutions below

0
On

Finally I have found a solution to this problem.

In the view.xml add following lines.

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

the upload url will be url to the neo destination. In the neo.app.json add the following lines.

{
  "path": "/cmis",
  "target": {
    "type": "destination",
    "name": "documentservice"
  },
  "description": "documentservice"
}

In the controller.js add the following lines of code.

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

In the neo cloud, maintain the url for following configuration in destination tab.

https://testdaasi328160trial.hanatrial.ondemand.com/TestDaaS/cmis/json/repo-id

repo-id will be your repository key.

this will solve the problem. U will be able to upload and the document.

Regards, Pavan.