Reynevan
Reynevan

Reputation: 1545

Bing Visual Search C# SDK returns an empty response

I'm trying to make a simple tool that uses the Bing Visual Search API thingy. I'm following this guide to set up the SDK, but the API response seems to be pretty much empty no matter which image I pass to that Search method:

var ms = await DownloadStream(img);
var res = await client.Images.VisualSearchMethodAsync(image: ms, knowledgeRequest: (string)null);

I also thought it might be caused by the auth not being correct, but it seems to return 200, so I'm not sure anymore.

The response body only shows the basic stuff and one empty tag:

{"_type": "ImageKnowledge", "instrumentation": {"_type": "ResponseInstrumentation"}, "tags": [{"displayName": "", "actions": [{"actionType": "MoreSizes"}, {"actionType": "ImageById"}]}], "image": {"imageInsightsToken": ""}}

I'm using that 7 day trial subscription and I tried authenticating with both keys it gave me.

Am I missing something here?

Edit:

Here's the download function. It downloads .png attachments from Discord links:

static async Task<MemoryStream> DownloadStream(string url)
{
    var ms = new MemoryStream();
    using (var http = new HttpClient())
    using (var res = await http.GetAsync(url))
        if (res.IsSuccessStatusCode)
        {
            await res.Content.CopyToAsync(ms);
            ms.Position = 0;
        }
    return ms;
}

An example of a link: https://cdn.discordapp.com/attachments/462686437331042306/462987122203295754/61A88kq3rJL.SY355.jpg

Upvotes: 0

Views: 192

Answers (1)

skao
skao

Reputation: 26

You're right in thinking that authentication isn't an issue, because you're getting some sort of JSON response--it would be a 401 error otherwise. This empty response happens when there's a problem with your file format and the API doesn't recognize that the stream you're passing in is an image. (If you uploaded a .txt file you would get this same empty response.)

If you post the code to your DownloadStream function, we might be able to help you debug further.

Upvotes: 1

Related Questions