Andre Carneiro
Andre Carneiro

Reputation: 736

Cognitive Emotions Video - how to send video to body

I need to send video from disk to Cognitive Services Emotion. I have almost done, but I was not capable to figure out how to format body properly and I can´t use '{url: http://...}' because I can´t expose the videos I want to submit. My code:

$.ajax({
            "headers":{
                "Content-Type":"application/octet-stream",
                "Ocp-Apim-Subscription-Key":"SECRET"
            },        
            type: "POST",
            url: url,
            "data": JSON.stringify({video: data}),
            success: (x,stat,res) => {
            },
            error: (res) => {
            }
        });

As you can see I´ve tried to use 'octet-stream' to send the video. And that is one of many ways I did it. I don´t know if I need to send a JSON(similar when you send url) or do something else. I couldn´t find anything about it on official documentation. Help??

Thanks!

Upvotes: 0

Views: 63

Answers (1)

cthrash
cthrash

Reputation: 2973

Please take a look at Sending binary data in javascript over HTTP.

$.ajax({
            "headers":{
                "Content-Type":"application/octet-stream",
                "Ocp-Apim-Subscription-Key":"SECRET"
            },        
            type: "POST",
            url: url,
            data: data,
            success: (x,stat,res) => {
            },
            error: (res) => {
            }
        });

You want the body payload to be the raw (unencoded) binary data for Cognitive Services. The accepted formats are listed here.

One other important thing to remember is that jQuery calls the error handler for HTTP 202 responses, which is what you get from this API. So your error handler needs to handle that case, or, more to the point, your success handler won't ever be called.

Upvotes: 0

Related Questions