Showing results for 
Search instead for 
Did you mean: 

Calling Microsoft Cognitive REST API in SAPUI5

0 Kudos

I am trying to call the form-recognizer API using SAPUI5 (Jquery / AJAX) post method. I am able to read the same pdf using RESTAPI client. The API when called from Javascript gives the below error.

The issue seems to be around data in the body of the ajax post method. Any suggestion/help is highly appreciated.

Error Message : 415 Unsupported Media Type {"error":{"code":"2018","innerError":{"requestId":"a12dc9f8-b22f-4602-85d8-7330b16593f7"},"message":"Content parsing error."}}

Javascript code :

  onChange: function(oEvent) {
  //  var that = this;
    var reader = new FileReader();
    var file = oEvent.getParameter("files")[0];
    var raw;

    reader.onload = function(e) {
        raw =;
        var sUrl2 = "{mymodelid>/analyze";

        type    : "POST",
        url     : sUrl2,
        context : this, 
        crossDomain: true,
        data: raw,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("content-type", "application/pdf");

            xhr.setRequestHeader("ocp-apim-subscription-key", "my-subscription id");
        error   : function(jqXHR, textStatus, errorThrown) {
        success : function(oData, status, jqXHR) {;


    reader.onerror = function(e) {"error");



Accepted Solutions (0)

Answers (0)