3
votes

I have noticed a rather strange error with the Emotion API from the Cognitive Services suite.

Everything works just fine as long as I send it URL's. When sending it image attachments. I receive this JSON error: { error: { code: 'InvalidImageSize', message: 'Image size is too small or too big.' } }

Sending it smaller or larger versions does not help. Send a URL of the same image, and suddenly it works fine again.

I stream the attachment to the API service in the exact same way I do for another Cognitive Services API, namely Computer Vision. And that works great with streamed attachments.

The code is on GitHub: https://github.com/sebsylvester/botbuilder-mcs

I know the APIs are still in preview, but this is still a weird issue.

1

1 Answers

2
votes

Unfortunately, the Emotion and Face APIs do not support chunked transfers, as noted here. The 'workaround' is to load the image bits synchronously prior to making the web request. The code snippet from that project is thus:

function _postImageSync(url, image, options) {
    return new _Promise(function (resolve, reject) {
        request.post({
            uri: host + rootPath + url,
            headers: {
                'Ocp-Apim-Subscription-Key': key,
                'Content-Type': 'application/octet-stream'
            },
            qs: options,
            body: fs.readFileSync(image)
        }, (error, response) => {
            response.body = JSON.parse(response.body);
            _return(error, response, resolve, reject);
        });
    });
}