Content Server 20.3 - unable to upload a document to a specific folder using the REST API

We are trying to create a new node in Content Server by uploading a file from a local source. We want to put the document in a specific Content Server folder that we created in the Enterprise Workspace.

We tried:

POST with  application/x-www-form-urlencoded

  • with body: {"file":"D:\\Temp\\project_26.docx","parent_id:":"31622","name":"project_26.docx","type":"144"}
  • with body {"parent_id:":"31622","name":"project_26.docx","type":"144"} and parameter file

We got the following error:

   {"error": "Error: File could not be found within the upload directory."}


We tried multipart/form-data with the following parts:

  • parent_id
  • type
  • name
  • file - binary data

We got the following error:

    {"error":"Missing required parameter \u0027Parent ID\u0027"}


Questions:

  • It is possible to create a node with a file uploaded from a local system?
  • What is the upload directory? It's shared or private to the Content Server?
  • Is there any configuration required in Content Server to enable this?


Comments

  • Typically with JavaScript one actually puts a "file" object. In postman one does not type the file as in a string but uses a file object. I don't know what you mean by a local file

    JS would look something like

    var params = {
     name: 'example',
     type: 144,
     parent_id: 123456
    }
    var content = new File(['example'], 'example.txt', { type: 'text/plain' })
    var formData = new FormData()
    formData.append('body', JSON.stringify(params))
    formData.append('file', content)
    $.ajax({
     method: 'POST',
     url: '.../api/v2/nodes',
     data: formData,
     contentType: false,
     processData: false,
     headers: { otcsticket: '...' }
    }).then(function (response) {
     console.log('success:', response)
    }, function (jqxhr) {
     console.log('failure:', jqxhr.responseJSON)
    })
    

    a HTML file with some buttons so you can browse to a file where it takes you. This used to work

    sorry did not test

    CS cannot accept a file like in a UNC or a drive path it has to come via the webserver's temp or the upload directory both are temporary places where a file can be provided to the webserver.

    the file I am giving comes from this thread

    fakeurlhttps://knowledge.opentext.com/knowledge/llisapi.dll?func=ll&objId=76349370&objAction=viewincontainer&_ga=2.243711431.371495072.1638830544-32732423.1638490313

    there should be other samples including postman screencaps in here many times people go wrong by doing a drive letter

  • Here is a better attempt at putting a file using POSTMAN.I use the file parameter and browse to a UNC share I have access

    the code for JS hence becomes

    var form = new FormData();
    form.append("type", "144");
    form.append("parent_id", "102893");
    form.append("name", "Filename for CS");
    form.append("file", fileInput.files[0], "///MYUNCSERVER/softwaredownloads/software/Useful/REST API Examples.postman_collection.json");
    
    var settings = {
      "url": "http://restserver:8080/OTCS/cs.exe/api/v1/nodes",
     "method": "POST",
     "timeout": 0,
     "headers": {
      "otcsticket": "QiQP"
     },
     "processData": false,
     "mimeType": "multipart/form-data",
     "contentType": false,
     "data": form
    };
    
    $.ajax(settings).done(function (response) {
     console.log(response);
    });
    
    
    

    CURL

    curl --location --request POST 'http://resetserver:8080/OTCS/cs.exe/api/v1/nodes' \
    --header 'otcsticket: QiQPcgfj73' \
    --form 'type="144"' \
    --form 'parent_id="102893"' \
    --form 'name="Filename for CS"' \
    --form 'file=@"///uncserver/softwaredownloads/software/Useful/REST API Examples.postman_collection.json"'