Skip to content

Commit a0abe6c

Browse files
author
dksimpson
committed
Refresh Bing Visual Search REST API quickstarts
1 parent 82238b7 commit a0abe6c

File tree

7 files changed

+90
-77
lines changed

7 files changed

+90
-77
lines changed

articles/cognitive-services/bing-visual-search/quickstarts/csharp.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ manager: nitinme
99
ms.service: cognitive-services
1010
ms.subservice: bing-visual-search
1111
ms.topic: quickstart
12-
ms.date: 12/17/2019
12+
ms.date: 05/19/2020
1313
ms.author: scottwhi
1414
---
1515

1616
# Quickstart: Get image insights using the Bing Visual Search REST API and C#
1717

18-
This quickstart demonstrates how to upload an image to the Bing Visual Search API and to view the insights that it returns.
18+
This quickstart demonstrates how to upload an image to the Bing Visual Search API and view the insights that it returns.
1919

2020
## Prerequisites
2121

@@ -37,7 +37,7 @@ This quickstart demonstrates how to upload an image to the Bing Visual Search AP
3737
using System.Collections.Generic;
3838
```
3939

40-
2. Add variables for your subscription key, endpoint, and path to the image you want to upload. `uriBase` can be the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource:
40+
2. Add variables for your subscription key, endpoint, and path to the image you want to upload. You can use the value of `uriBase` in the following code for the global endpoint, or use the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource:
4141

4242
```csharp
4343
const string accessKey = "<my_subscription_key>";
@@ -65,7 +65,7 @@ This quickstart demonstrates how to upload an image to the Bing Visual Search AP
6565

6666
## Build the form data
6767

68-
To upload a local image, you first build the form data to send to the API. The form data must include the `Content-Disposition` header, its `name` parameter must be set to "image", and the `filename` parameter can be set to any string. The contents of the form contain the binary data of the image. The maximum image size you can upload is 1 MB.
68+
1. To upload a local image, first build the form data to send to the API. The form data includes the `Content-Disposition` header, the `name` parameter set to "image", and the `filename` parameter set to any string. The contents of the form contain the binary data of the image. The maximum image size you can upload is 1 MB.
6969

7070
```
7171
--boundary_1234-abcd
@@ -76,7 +76,7 @@ To upload a local image, you first build the form data to send to the API. The f
7676
--boundary_1234-abcd--
7777
```
7878

79-
1. Add boundary strings to format the POST form data. Boundary strings determine the start, end, and newline characters for the data:
79+
2. Add boundary strings to format the POST form data. Boundary strings determine the start, end, and newline characters for the data:
8080

8181
```csharp
8282
// Boundary strings for form data in body of POST.
@@ -86,14 +86,14 @@ To upload a local image, you first build the form data to send to the API. The f
8686
static string EndBoundaryTemplate = "--{0}--";
8787
```
8888

89-
2. Use the following variables to add parameters to the form data:
89+
3. Use the following variables to add parameters to the form data:
9090

9191
```csharp
9292
const string CONTENT_TYPE_HEADER_PARAMS = "multipart/form-data; boundary={0}";
9393
const string POST_BODY_DISPOSITION_HEADER = "Content-Disposition: form-data; name=\"image\"; filename=\"{0}\"" + CRLF +CRLF;
9494
```
9595

96-
3. Create a function named `BuildFormDataStart()` to create the start of the form data using the boundary strings and image path:
96+
4. Create a function named `BuildFormDataStart()` to create the start of the form data using the boundary strings and image path:
9797

9898
```csharp
9999
static string BuildFormDataStart(string boundary, string filename)
@@ -107,7 +107,7 @@ To upload a local image, you first build the form data to send to the API. The f
107107
}
108108
```
109109

110-
4. Create a function named `BuildFormDataEnd()` to create the end of the form data using the boundary strings:
110+
5. Create a function named `BuildFormDataEnd()` to create the end of the form data using the boundary strings:
111111

112112
```csharp
113113
static string BuildFormDataEnd(string boundary)
@@ -122,7 +122,7 @@ To upload a local image, you first build the form data to send to the API. The f
122122

123123
2. Use a `WebRequest` to store your URI, contentType value, and headers.
124124

125-
3. Use `request.GetRequestStream()` to write your form and image data, then get the response. Your function should be similar to the one below:
125+
3. Use `request.GetRequestStream()` to write your form and image data, and then get the response. Your function should be similar to the following code:
126126

127127
```csharp
128128
static string BingImageSearch(string startFormData, string endFormData, byte[] image, string contentTypeValue)
@@ -154,14 +154,14 @@ To upload a local image, you first build the form data to send to the API. The f
154154

155155
## Create the Main method
156156

157-
1. In the `Main` method of your application, get the filename and binary data of your image:
157+
1. In the `Main()` method of your application, get the filename and binary data of your image:
158158

159159
```csharp
160160
var filename = GetImageFileName(imagePath);
161161
var imageBinary = GetImageBinary(imagePath);
162162
```
163163

164-
2. Set up the POST body by formatting the boundary for it. Then call `startFormData()` and `endFormData` to create the form data:
164+
2. Set up the POST body by formatting the boundary for it. Then, call `startFormData()` and `endFormData` to create the form data:
165165

166166
```csharp
167167
// Set up POST body.
@@ -176,7 +176,7 @@ To upload a local image, you first build the form data to send to the API. The f
176176
var contentTypeHdrValue = string.Format(CONTENT_TYPE_HEADER_PARAMS, boundary);
177177
```
178178

179-
4. Get the API response by calling `BingImageSearch()` and print the response:
179+
4. Get the API response by calling `BingImageSearch()`, and then print the response:
180180

181181
```csharp
182182
var json = BingImageSearch(startFormData, endFormData, imageBinary, contentTypeHdrValue);
@@ -187,9 +187,9 @@ To upload a local image, you first build the form data to send to the API. The f
187187

188188
## Using HttpClient
189189

190-
If you use `HttpClient`, you can use the `MultipartFormDataContent` class to build the form data. Just use the following sections of code to replace the corresponding methods in the previous example.
190+
If you use `HttpClient`, you can use the `MultipartFormDataContent` class to build the form data. Use the following sections of code to replace the corresponding methods in the previous example.
191191

192-
Replace the `Main` method with this code:
192+
Replace the `Main()` method with this code:
193193

194194
```csharp
195195
static void Main()
@@ -229,7 +229,7 @@ Replace the `Main` method with this code:
229229
}
230230
```
231231

232-
Replace the `BingImageSearch` method with this code:
232+
Replace the `BingImageSearch()` method with this code:
233233

234234
```csharp
235235
/// <summary>

articles/cognitive-services/bing-visual-search/quickstarts/go.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ manager: nitinme
99
ms.service: cognitive-services
1010
ms.subservice: bing-visual-search
1111
ms.topic: quickstart
12-
ms.date: 12/17/2019
12+
ms.date: 05/19/2020
1313
ms.author: aahi
1414
---
1515

@@ -20,13 +20,13 @@ This quickstart uses the Go programming language to call the Bing Visual Search
2020
## Prerequisites
2121

2222
* Install the [Go binaries](https://golang.org/dl/).
23-
* The go-spew deep pretty printer is used to display results. You can install go-spew with the `$ go get -u https://github.com/davecgh/go-spew` command.
23+
* The go-spew deep pretty printer, which is used to display results. Install go-spew with the `$ go get -u https://github.com/davecgh/go-spew` command.
2424

2525
[!INCLUDE [cognitive-services-bing-visual-search-signup-requirements](../../../../includes/cognitive-services-bing-visual-search-signup-requirements.md)]
2626

2727
## Project and libraries
2828

29-
Create a Go project in your IDE or editor. Then import `net/http` for requests, `ioutil` to read the response, and `encoding/json` to handle the JSON text of results. The `go-spew` library is used to parse JSON results.
29+
Create a Go project in your IDE or editor. Then, import `net/http` for requests, `ioutil` to read the response, and `encoding/json` to handle the JSON text of results. Use the `go-spew` library to parse JSON results.
3030

3131
```go
3232
package main
@@ -105,7 +105,12 @@ type BingAnswer struct {
105105

106106
## Main function and variables
107107

108-
The following code declares the main function and assigns required variables. Confirm that the endpoint is correct and replace the `token` value with a valid subscription key from your Azure account. The `batchNumber` is a GUID required for leading and trailing boundaries of the POST data. The `fileName` variable identifies the image file for the POST. `endpoint` can be the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource:
108+
The following code declares the main function and assigns the required variables:
109+
110+
1. Confirm that the endpoint is correct and replace the `token` value with a valid subscription key from your Azure account.
111+
2. For `batchNumber`, assign a GUID, which is required for the leading and trailing boundaries of the POST data.
112+
3. For `fileName`, assign the image file to use for the POST.
113+
4. For `endpoint`, you can use the global endpoint in the following code, or use the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
109114

110115
```go
111116
func main() {
@@ -155,7 +160,12 @@ func main() {
155160

156161
## Boundaries of POST body
157162

158-
A POST request to the Visual Search endpoint requires leading and trailing boundaries enclosing the POST data. The leading boundary includes a batch number, the content type identifier `Content-Disposition: form-data; name="image"; filename=`, plus the filename of the image to POST. The trailing boundary is simply the batch number. These functions are not included in the `main` block:
163+
A POST request to the Visual Search endpoint requires leading and trailing boundaries to enclose the POST data. These functions aren't included in the `main()` block.
164+
165+
The leading boundary includes a batch number, the content type identifier `Content-Disposition: form-data; name="image"; filename=`, and the filename of the image to POST.
166+
167+
The trailing boundary includes the batch number only.
168+
159169

160170
```go
161171
func BuildFormDataStart(batNum string, fileName string) string{

articles/cognitive-services/bing-visual-search/quickstarts/java.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ manager: nitinme
99
ms.service: cognitive-services
1010
ms.subservice: bing-visual-search
1111
ms.topic: quickstart
12-
ms.date: 12/17/2019
12+
ms.date: 05/19/2020
1313
ms.author: scottwhi
1414
---
1515

1616
# Quickstart: Get image insights using the Bing Visual Search REST API and Java
1717

18-
Use this quickstart to make your first call to the Bing Visual Search API and view the results. This Java application uploads an image to the API and displays the information it returns. Though this application is written in Java, the API is a RESTful Web service compatible with most programming languages.
18+
Use this quickstart to make your first call to the Bing Visual Search API. This Java application uploads an image to the API and displays the information it returns. Although this application is written in Java, the API is a RESTful Web service compatible with most programming languages.
1919

2020
## Prerequisites
2121

@@ -48,7 +48,7 @@ Use this quickstart to make your first call to the Bing Visual Search API and vi
4848
import org.apache.http.impl.client.HttpClientBuilder;
4949
```
5050

51-
2. Create variables for your API endpoint, subscription key, and the path to your image. `endpoint` can be the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource:
51+
2. Create variables for your API endpoint, subscription key, and the path to your image. You can use the value of `endpoint` in the following code for the global endpoint, or use the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource:
5252

5353
```java
5454
static String endpoint = "https://api.cognitive.microsoft.com/bing/v7.0/images/visualsearch";
@@ -57,7 +57,7 @@ Use this quickstart to make your first call to the Bing Visual Search API and vi
5757
```
5858

5959

60-
When you upload a local image, the form data must include the `Content-Disposition` header. You must set its `name` parameter to "image", and you can set the `filename` parameter to any string. The contents of the form include the binary data of the image. The maximum image size you can upload is 1 MB.
60+
3. When you upload a local image, the form data must include the `Content-Disposition` header. Set its `name` parameter to "image", and set the `filename` parameter to any string. The contents of the form include the binary data of the image. The maximum image size you can upload is 1 MB.
6161

6262
```
6363
--boundary_1234-abcd
@@ -70,7 +70,7 @@ Use this quickstart to make your first call to the Bing Visual Search API and vi
7070
7171
## Create the JSON parser
7272
73-
Create a method to make the JSON response from the API more readable using `JsonParser`:
73+
Create a method to make the JSON response from the API more readable by using `JsonParser`:
7474
7575
```java
7676
public static String prettify(String json_text) {

articles/cognitive-services/bing-visual-search/quickstarts/nodejs.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ manager: nitinme
99
ms.service: cognitive-services
1010
ms.subservice: bing-visual-search
1111
ms.topic: quickstart
12-
ms.date: 12/17/2019
12+
ms.date: 05/19/2020
1313
ms.author: scottwhi
1414
---
1515

1616
# Quickstart: Get image insights using the Bing Visual Search REST API and Node.js
1717

18-
Use this quickstart to make your first call to the Bing Visual Search API and view the search results. This simple JavaScript application uploads an image to the API, and displays the information returned about it. While this application is written in JavaScript, the API is a RESTful Web service compatible with most programming languages.
18+
Use this quickstart to make your first call to the Bing Visual Search API. This simple JavaScript application uploads an image to the API, and displays the information returned about it. Although this application is written in JavaScript, the API is a RESTful Web service compatible with most programming languages.
1919

2020
## Prerequisites
2121

@@ -35,7 +35,7 @@ Use this quickstart to make your first call to the Bing Visual Search API and vi
3535
var fs = require('fs');
3636
```
3737

38-
2. Create variables for your API endpoint, subscription key, and the path to your image. `baseUri` can be the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource:
38+
2. Create variables for your API endpoint, subscription key, and the path to your image. You can use the value of `baseUri` in the following code for the global endpoint, or use the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource:
3939

4040
```javascript
4141
var baseUri = 'https://api.cognitive.microsoft.com/bing/v7.0/images/visualsearch';
@@ -53,7 +53,7 @@ Use this quickstart to make your first call to the Bing Visual Search API and vi
5353

5454
## Construct and send the search request
5555

56-
When uploading a local image, the form data must include the `Content-Disposition` header. You must set its `name` parameter to "image", and the `filename` parameter can be set to any string. The contents of the form include the binary data of the image. The maximum image size you may upload is 1 MB.
56+
When you upload a local image, the form data must include the `Content-Disposition` header. Set its `name` parameter to "image", and set the `filename` parameter to any string. The contents of the form include the binary data of the image. The maximum image size you can upload is 1 MB.
5757

5858
```
5959
--boundary_1234-abcd
@@ -64,14 +64,14 @@ Content-Disposition: form-data; name="image"; filename="myimagefile.jpg"
6464
--boundary_1234-abcd--
6565
```
6666
67-
1. Create a new **FormData** object using `FormData()`, and append your image path to it, using `fs.createReadStream()`:
67+
1. Create a new **FormData** object using `FormData()`, and append your image path to it by using `fs.createReadStream()`:
6868
6969
```javascript
7070
var form = new FormData();
7171
form.append("image", fs.createReadStream(imagePath));
7272
```
7373
74-
2. Use the request library to upload the image, and call `requestCallback()` to print the response. Be sure to add your subscription key to the request header:
74+
2. Use the request library to upload the image, and call `requestCallback()` to print the response. Add your subscription key to the request header:
7575
7676
```javascript
7777
form.getLength(function(err, length){

articles/cognitive-services/bing-visual-search/quickstarts/python.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ manager: nitinme
99
ms.service: cognitive-services
1010
ms.subservice: bing-visual-search
1111
ms.topic: quickstart
12-
ms.date: 12/17/2019
12+
ms.date: 05/19/2020
1313
ms.author: scottwhi
1414
---
1515

1616
# Quickstart: Get image insights using the Bing Visual Search REST API and Python
1717

18-
Use this quickstart to make your first call to the Bing Visual Search API and view the results. This Python application uploads an image to the API and displays the information it returns. Though this application is written in Python, the API is a RESTful Web service compatible with most programming languages.
18+
Use this quickstart to make your first call to the Bing Visual Search API. This Python application uploads an image to the API and displays the information it returns. Although this application is written in Python, the API is a RESTful Web service compatible with most programming languages.
1919

2020
## Prerequisites
2121

@@ -31,7 +31,7 @@ Use this quickstart to make your first call to the Bing Visual Search API and vi
3131
import requests, json
3232
```
3333

34-
2. Create variables for your subscription key, endpoint, and the path to the image you're uploading. `BASE_URI` can be the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource:
34+
2. Create variables for your subscription key, endpoint, and the path to the image you're uploading. You can use the value of `BASE_URI` in the following code for the global endpoint, or use the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
3535

3636
```python
3737

@@ -40,7 +40,7 @@ Use this quickstart to make your first call to the Bing Visual Search API and vi
4040
imagePath = 'your-image-path'
4141
```
4242

43-
When you upload a local image, the form data must include the `Content-Disposition` header. You must set its `name` parameter to "image", and you can set the `filename` parameter to any string. The contents of the form include the binary data of the image. The maximum image size you can upload is 1 MB.
43+
3. When you upload a local image, the form data must include the `Content-Disposition` header. Set its `name` parameter to "image", and set the `filename` parameter to any string. The contents of the form include the binary data of the image. The maximum image size you can upload is 1 MB.
4444

4545
```
4646
--boundary_1234-abcd
@@ -51,13 +51,13 @@ Use this quickstart to make your first call to the Bing Visual Search API and vi
5151
--boundary_1234-abcd--
5252
```
5353

54-
3. Create a dictionary object to hold your request's header information. Bind your subscription key to the string `Ocp-Apim-Subscription-Key`, as shown below:
54+
4. Create a dictionary object to hold your request's header information. Bind your subscription key to the string `Ocp-Apim-Subscription-Key`:
5555

5656
```python
5757
HEADERS = {'Ocp-Apim-Subscription-Key': SUBSCRIPTION_KEY}
5858
```
5959

60-
4. Create another dictionary to contain your image, which is opened and uploaded when you send the request:
60+
5. Create another dictionary to contain your image, which is opened and uploaded when you send the request:
6161

6262
```python
6363
file = {'image' : ('myfile', open(imagePath, 'rb'))}

0 commit comments

Comments
 (0)