Skip to content

Commit 6d9074d

Browse files
Edits
1 parent e241d80 commit 6d9074d

File tree

1 file changed

+28
-77
lines changed

1 file changed

+28
-77
lines changed

articles/storage/blobs/storage-blob-tags-javascript.md

Lines changed: 28 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to categorize, manage, and query for blob objects by usin
55
services: storage
66
author: pauljewellmsft
77
ms.author: pauljewell
8-
ms.date: 08/05/2024
8+
ms.date: 10/23/2024
99
ms.service: azure-blob-storage
1010
ms.topic: how-to
1111
ms.devlang: javascript
@@ -38,27 +38,17 @@ To set tags at blob upload time, create a [BlobClient](storage-blob-javascript-g
3838

3939
The following example performs this task.
4040

41-
```javascript
42-
// A blob can have up to 10 tags.
43-
//
44-
// const tags = {
45-
// project: 'End of month billing summary',
46-
// reportOwner: 'John Doe',
47-
// reportPresented: 'April 2022'
48-
// }
49-
async function setTags(containerClient, blobName, tags) {
41+
### [JavaScript](#tab/javascript)
5042

51-
// Create blob client from container client
52-
const blockBlobClient = await containerClient.getBlockBlobClient(blobName);
43+
:::code language="javascript" source="~/azure-storage-snippets/blobs/howto/JavaScript/NodeJS-v12/dev-guide/set-and-retrieve-blob-tags.js" id="Snippet_setTags":::
5344

54-
// Set tags
55-
await blockBlobClient.setTags(tags);
45+
### [TypeScript](#tab/typescript)
5646

57-
console.log(`uploading blob ${blobName}`);
58-
}
59-
```
47+
:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-set-tags.ts" id="Snippet_setTags" :::
6048

61-
You can delete all tags by passing an empty JSON object into the setTags method.
49+
---
50+
51+
You can delete all tags by passing an empty JSON object into the `setTags` method.
6252

6353
| Related articles |
6454
|--|
@@ -75,21 +65,15 @@ To get tags, create a [BlobClient](storage-blob-javascript-get-started.md#create
7565

7666
The following example shows how to get and iterate over the blob's tags.
7767

78-
```javascript
79-
async function getTags(containerClient, blobName) {
68+
### [JavaScript](#tab/javascript)
8069

81-
// Create blob client from container client
82-
const blockBlobClient = await containerClient.getBlockBlobClient(blobName);
70+
:::code language="javascript" source="~/azure-storage-snippets/blobs/howto/JavaScript/NodeJS-v12/dev-guide/set-and-retrieve-blob-tags.js" id="Snippet_getTags":::
8371

84-
// Get tags
85-
const result = await blockBlobClient.getTags();
72+
### [TypeScript](#tab/typescript)
8673

87-
for (const tag in result.tags) {
74+
:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-set-tags.ts" id="Snippet_getTags" :::
8875

89-
console.log(`TAG: ${tag}: ${result.tags[tag]}`);
90-
}
91-
}
92-
```
76+
---
9377

9478
## Filter and find data with blob index tags
9579

@@ -113,54 +97,17 @@ To find blobs, create a [BlobClient](storage-blob-javascript-get-started.md#crea
11397

11498
- [BlobServiceClient.findBlobsByTags](/javascript/api/@azure/storage-blob/blobserviceclient#@azure-storage-blob-blobserviceclient-findblobsbytags)
11599

116-
The following example finds all blobs matching the tagOdataQuery parameter.
117-
118-
```javascript
119-
async function findBlobsByQuery(blobServiceClient, tagOdataQuery) {
120-
121-
// page size
122-
const maxPageSize = 10;
123-
124-
let i = 1;
125-
let marker;
126-
127-
const listOptions = {
128-
includeMetadata: true,
129-
includeSnapshots: false,
130-
includeTags: true,
131-
includeVersions: false
132-
};
133-
134-
let iterator = blobServiceClient.findBlobsByTags(tagOdataQuery, listOptions).byPage({ maxPageSize });
135-
let response = (await iterator.next()).value;
136-
137-
// Prints blob names
138-
if (response.blobs) {
139-
for (const blob of response.blobs) {
140-
console.log(`Blob ${i++}: ${blob.name} - ${JSON.stringify(blob.tags)}`);
141-
}
142-
}
143-
144-
// Gets next marker
145-
marker = response.continuationToken;
146-
147-
// no more blobs
148-
if (!marker) return;
149-
150-
// Passing next marker as continuationToken
151-
iterator = blobServiceClient
152-
.findBlobsByTags(tagOdataQuery, listOptions)
153-
.byPage({ continuationToken: marker, maxPageSize });
154-
response = (await iterator.next()).value;
155-
156-
// Prints blob names
157-
if (response.blobs) {
158-
for (const blob of response.blobs) {
159-
console.log(`Blob ${i++}: ${blob.name} - ${JSON.stringify(blob.tags)}`);
160-
}
161-
}
162-
}
163-
```
100+
The following example finds all blobs matching the `tagOdataQuery` parameter.
101+
102+
### [JavaScript](#tab/javascript)
103+
104+
:::code language="javascript" source="~/azure-storage-snippets/blobs/howto/JavaScript/NodeJS-v12/dev-guide/set-and-retrieve-blob-tags.js" id="Snippet_findBlobsByQuery":::
105+
106+
### [TypeScript](#tab/typescript)
107+
108+
:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-set-and-retrieve-tags.ts" id="Snippet_findBlobsByQuery" :::
109+
110+
---
164111

165112
And example output for this function shows the matched blobs and their tags, based on the console.log code in the preceding function:
166113

@@ -172,6 +119,10 @@ And example output for this function shows the matched blobs and their tags, bas
172119

173120
To learn more about how to use index tags to manage and find data using the Azure Blob Storage client library for JavaScript, see the following resources.
174121

122+
### Code samples
123+
124+
- View [JavaScript](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/JavaScript/NodeJS-v12/dev-guide/set-and-retrieve-blob-tags.js) and [TypeScript](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-set-and-retrieve-tags.ts) code samples from this article (GitHub)
125+
175126
### REST API operations
176127

177128
The Azure SDK for JavaScript contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar JavaScript paradigms. The client library methods for managing and using blob index tags use the following REST API operations:

0 commit comments

Comments
 (0)