Emotion Video API (Javascript)

Category: project oxford


rtwati on Wed, 06 Jul 2016 02:20:10

Hi All,

I am looking in this forum that how to read the Operation-Location header from response but none of the answers could get me the result. Could you please help me to read the Operation-Location so I can check the status of video and get the results of emotions of video. Without this location I am not able to query the api. Below are my code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

        <script type="text/javascript">
            $(function () {
                var params = {
                    // Request parameters
                    url: "https://api.projectoxford.ai/emotion/v1.0/recognizeinvideo?" + $.param(params),
                    beforeSend: function (xhrObj) {
                        // Request headers
                        xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", "cd70815cbe9a4a75be6d0e0f********");
                    type: "POST",
                    contentType: "application/json",
                    data: "{'url': 'http://view.vzaar.com/6812344/video'}",
                    dataType: "json",
                        .done(function (response) {
                        .fail(function (response) {


When I check in log below is output.

Cache-Control: no-cache
Pragma: no-cache
Expires: -1

And even the the request is accepted it call the function fail instead of done. Am i doing anything wrong in this code. Please help me I am stuck in this.



cthrash99 on Thu, 07 Jul 2016 03:32:09

Hi rtwati, there are two things happening here.

First, it is a jQuery idiosyncracy that an HTTP 202 response triggers the fail() method, presumably because your status is "Accepted", which is not the same as 'done'.  So you'll want to check for a response.status in the fail() handler and see if the value is 202.

Second (which makes the first point moot) is that while the Operation-Location header is in the HTTP response, because this is a CORS request, headers that aren't convered by the (additional) Access-Control-Expose-Headers will not be included in the response.getAllResponseHeaders() result.  This requires a fix on the Cognitive Service backend; I am not aware of a workaround so long as you're using XHRs from Javascript.  For now I would suggest using someother language to access the service.