Skip to content

Commit b9b2479

Browse files
committed
Merge branch 'master' of https://github.com/MicrosoftDocs/azure-docs-pr into rolyon-rbac-arm-remove-update
2 parents d317851 + e1dbd3f commit b9b2479

File tree

8 files changed

+218
-202
lines changed

8 files changed

+218
-202
lines changed

articles/azure-maps/quick-demo-map-app.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: "Quickstart: Interactive map search with Azure Maps | Microsoft Azure Maps"
2+
title: "Quickstart: Interactive map search with Azure Maps"
33
description: Learn how to create a demo web application for interactive map search by using Microsoft Azure Maps web SDK.
44
author: philmea
55
ms.author: philmea
6-
ms.date: 1/14/2020
6+
ms.date: 5/21/2020
77
ms.topic: quickstart
88
ms.service: azure-maps
99
services: azure-maps
@@ -14,8 +14,9 @@ ms.custom: mvc
1414
# Quickstart: Create an interactive search map by using Azure Maps
1515

1616
This article demonstrates the capabilities of Azure Maps to create a map that gives users an interactive search experience. It walks you through these basic steps:
17+
1718
* Create your own Azure Maps account.
18-
* Get your account key to use in the demo web application.
19+
* Get your primary key to use in the demo web application.
1920

2021
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
2122

@@ -46,24 +47,27 @@ Create a new Maps account with the following steps:
4647

4748
## Get the primary key for your account
4849

49-
Once your Maps account is successfully created, retrieve the key that enables you to query the Maps APIs. We recommend using your account's primary key as the subscription key when calling Azure Maps services.
50+
Once your Maps account is successfully created, retrieve the primary key that enables you to query the Maps APIs.
5051

5152
1. Open your Maps account in the portal.
5253
2. In the settings section, select **Authentication**.
5354
3. Copy the **Primary Key** to your clipboard. Save it locally to use later in this tutorial.
5455

56+
>[!NOTE]
57+
> If you use the subscription key instead of the primary key, your map won't render properly. Also, for security purposes, it is recommended that you rotate between your primary and secondary keys. To rotate keys, update your app to use the secondary key, deploy, then press the cycle/refresh button beside the primary key to generate a new primary key. The old primary key will be disabled. For more information on key rotation, see [Set up Azure Key Vault with key rotation and auditing](https://docs.microsoft.com/azure/key-vault/secrets/key-rotation-log-monitoring)
58+
5559
![Get Primary Key Azure Maps key in Azure portal](./media/quick-demo-map-app/get-key.png)
5660

5761
## Download the application
5862

59-
1. Go to [interactiveSearch.html](https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/master/AzureMapsCodeSamples/Tutorials/interactiveSearch.html) and click it to view the contents within the GitHub User Interface. Right click on the **Raw** button and copy the content of the file or 'Save as' to download the file.
63+
1. Go to [interactiveSearch.html](https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/master/AzureMapsCodeSamples/Tutorials/interactiveSearch.html). Copy the content of the file.
6064
2. Save the contents of this file locally as **AzureMapDemo.html**. Open it in a text editor.
6165
3. Search for the string `<Your Azure Maps Key>`. Replace it with the **Primary Key** value from the preceding section.
6266

6367
## Open the application
6468

6569
1. Open the file **AzureMapDemo.html** in a browser of your choice.
66-
2. Observe the map shown of the City of Los Angeles. Zoom in and out to see how the map automatically renders with more or less information depending on the zoom level.
70+
2. Observe the map shown of the City of Los Angeles. Zoom in and out to see how the map automatically renders with more or less information depending on the zoom level.
6771
3. Change the default center of the map. In the **AzureMapDemo.html** file, search for the variable named **center**. Replace the longitude, latitude pair value for this variable with the new values **[-74.0060, 40.7128]**. Save the file and refresh your browser.
6872
4. Try out the interactive search experience. In the search box on the upper-left corner of the demo web application, search for **restaurants**.
6973
5. Move your mouse over the list of addresses and locations that appear below the search box. Notice how the corresponding pin on the map pops out information about that location. For privacy of private businesses, fictitious names and addresses are shown.
@@ -82,12 +86,12 @@ The tutorials detail how to use and configure Azure Maps with your account. Don'
8286
In this quickstart, you created your Azure Maps account and created a demo app. Take a look at the following tutorials to learn about Azure Maps:
8387

8488
> [!div class="nextstepaction"]
85-
> [Search nearby points of interest by using Azure Maps](tutorial-search-location.md)
89+
> [Search nearby points of interest with Azure Maps](tutorial-search-location.md)
8690
8791
For more code examples and an interactive coding experience, see these guides:
8892

8993
> [!div class="nextstepaction"]
90-
> [Find an address by using the Azure Maps search service](how-to-search-for-address.md)
94+
> [Find an address with Azure Maps search service](how-to-search-for-address.md)
9195
9296
> [!div class="nextstepaction"]
9397
> [Use the Azure Maps Map Control](how-to-use-map-control.md)

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

Lines changed: 90 additions & 90 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/22/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,15 +37,15 @@ 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. For the `uriBase` value, 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.
4141

4242
```csharp
4343
const string accessKey = "<my_subscription_key>";
4444
const string uriBase = "https://api.cognitive.microsoft.com/bing/v7.0/images/visualsearch";
4545
static string imagePath = @"<path_to_image>";
4646
```
4747

48-
3. Create a method named `GetImageFileName()` to get the path for your image:
48+
3. Create a method named `GetImageFileName()` to get the path for your image.
4949

5050
```csharp
5151
static string GetImageFileName(string path)
@@ -54,7 +54,7 @@ This quickstart demonstrates how to upload an image to the Bing Visual Search AP
5454
}
5555
```
5656

57-
4. Create a method to get the binary data of the image:
57+
4. Create a method to get the binary data of the image.
5858

5959
```csharp
6060
static byte[] GetImageBinary(string path)
@@ -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 the file name of the image. 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 by 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 by 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 its boundary. Then, call `BuildFormDataStart()` and `BuildFormDataEnd()` to create the form data.
165165

166166
```csharp
167167
// Set up POST body.
@@ -170,13 +170,13 @@ To upload a local image, you first build the form data to send to the API. The f
170170
var endFormData = BuildFormDataEnd(boundary);
171171
```
172172

173-
3. Create the `ContentType` value by formatting `CONTENT_TYPE_HEADER_PARAMS` and the form data boundary:
173+
3. Create the `ContentType` value by formatting `CONTENT_TYPE_HEADER_PARAMS` and the form data boundary.
174174

175175
```csharp
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,81 +187,81 @@ 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.
191-
192-
Replace the `Main` method with this code:
193-
194-
```csharp
195-
static void Main()
196-
{
197-
try
198-
{
199-
Console.OutputEncoding = System.Text.Encoding.UTF8;
200-
201-
if (accessKey.Length == 32)
202-
{
203-
if (IsImagePathSet(imagePath))
204-
{
205-
var filename = GetImageFileName(imagePath);
206-
Console.WriteLine("Getting image insights for image: " + filename);
207-
var imageBinary = GetImageBinary(imagePath);
208-
209-
var boundary = string.Format(BoundaryTemplate, Guid.NewGuid());
210-
var json = BingImageSearch(imageBinary, boundary, uriBase, accessKey);
211-
212-
Console.WriteLine("\nJSON Response:\n");
213-
Console.WriteLine(JsonPrettyPrint(json));
214-
}
215-
}
216-
else
217-
{
218-
Console.WriteLine("Invalid Bing Visual Search API subscription key!");
219-
Console.WriteLine("Please paste yours into the source code.");
220-
}
221-
222-
Console.Write("\nPress Enter to exit ");
223-
Console.ReadLine();
224-
}
225-
catch (Exception e)
226-
{
227-
Console.WriteLine(e.Message);
228-
}
229-
}
230-
```
231-
232-
Replace the `BingImageSearch` method with this code:
233-
234-
```csharp
235-
/// <summary>
236-
/// Calls the Bing visual search endpoint and returns the JSON response.
237-
/// </summary>
238-
static string BingImageSearch(byte[] image, string boundary, string uri, string subscriptionKey)
239-
{
240-
var requestMessage = new HttpRequestMessage(HttpMethod.Post, uri);
241-
requestMessage.Headers.Add("Ocp-Apim-Subscription-Key", accessKey);
242-
243-
var content = new MultipartFormDataContent(boundary);
244-
content.Add(new ByteArrayContent(image), "image", "myimage");
245-
requestMessage.Content = content;
246-
247-
var httpClient = new HttpClient();
248-
249-
Task<HttpResponseMessage> httpRequest = httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
250-
HttpResponseMessage httpResponse = httpRequest.Result;
251-
HttpStatusCode statusCode = httpResponse.StatusCode;
252-
HttpContent responseContent = httpResponse.Content;
253-
254-
string json = null;
255-
256-
if (responseContent != null)
257-
{
258-
Task<String> stringContentsTask = responseContent.ReadAsStringAsync();
259-
json = stringContentsTask.Result;
260-
}
261-
262-
return json;
263-
}
264-
```
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:
191+
192+
1. Replace the `Main()` method with the following code:
193+
194+
```csharp
195+
static void Main()
196+
{
197+
try
198+
{
199+
Console.OutputEncoding = System.Text.Encoding.UTF8;
200+
201+
if (accessKey.Length == 32)
202+
{
203+
if (IsImagePathSet(imagePath))
204+
{
205+
var filename = GetImageFileName(imagePath);
206+
Console.WriteLine("Getting image insights for image: " + filename);
207+
var imageBinary = GetImageBinary(imagePath);
208+
209+
var boundary = string.Format(BoundaryTemplate, Guid.NewGuid());
210+
var json = BingImageSearch(imageBinary, boundary, uriBase, accessKey);
211+
212+
Console.WriteLine("\nJSON Response:\n");
213+
Console.WriteLine(JsonPrettyPrint(json));
214+
}
215+
}
216+
else
217+
{
218+
Console.WriteLine("Invalid Bing Visual Search API subscription key!");
219+
Console.WriteLine("Please paste yours into the source code.");
220+
}
221+
222+
Console.Write("\nPress Enter to exit ");
223+
Console.ReadLine();
224+
}
225+
catch (Exception e)
226+
{
227+
Console.WriteLine(e.Message);
228+
}
229+
}
230+
```
231+
232+
2. Replace the `BingImageSearch()` method with the following code:
233+
234+
```csharp
235+
/// <summary>
236+
/// Calls the Bing visual search endpoint and returns the JSON response.
237+
/// </summary>
238+
static string BingImageSearch(byte[] image, string boundary, string uri, string subscriptionKey)
239+
{
240+
var requestMessage = new HttpRequestMessage(HttpMethod.Post, uri);
241+
requestMessage.Headers.Add("Ocp-Apim-Subscription-Key", accessKey);
242+
243+
var content = new MultipartFormDataContent(boundary);
244+
content.Add(new ByteArrayContent(image), "image", "myimage");
245+
requestMessage.Content = content;
246+
247+
var httpClient = new HttpClient();
248+
249+
Task<HttpResponseMessage> httpRequest = httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
250+
HttpResponseMessage httpResponse = httpRequest.Result;
251+
HttpStatusCode statusCode = httpResponse.StatusCode;
252+
HttpContent responseContent = httpResponse.Content;
253+
254+
string json = null;
255+
256+
if (responseContent != null)
257+
{
258+
Task<String> stringContentsTask = responseContent.ReadAsStringAsync();
259+
json = stringContentsTask.Result;
260+
}
261+
262+
return json;
263+
}
264+
```
265265

266266
## Next steps
267267

0 commit comments

Comments
 (0)