@@ -5,7 +5,7 @@ description: Learn how to categorize, manage, and query for blob objects by usin
5
5
services : storage
6
6
author : pauljewellmsft
7
7
ms.author : pauljewell
8
- ms.date : 08/05 /2024
8
+ ms.date : 10/23 /2024
9
9
ms.service : azure-blob-storage
10
10
ms.topic : how-to
11
11
ms.devlang : javascript
@@ -38,27 +38,17 @@ To set tags at blob upload time, create a [BlobClient](storage-blob-javascript-g
38
38
39
39
The following example performs this task.
40
40
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 )
50
42
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":::
53
44
54
- // Set tags
55
- await blockBlobClient .setTags (tags);
45
+ ### [ TypeScript] ( #tab/typescript )
56
46
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" :::
60
48
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.
62
52
63
53
| Related articles |
64
54
| --|
@@ -75,21 +65,15 @@ To get tags, create a [BlobClient](storage-blob-javascript-get-started.md#create
75
65
76
66
The following example shows how to get and iterate over the blob's tags.
77
67
78
- ``` javascript
79
- async function getTags (containerClient , blobName ) {
68
+ ### [ JavaScript] ( #tab/javascript )
80
69
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":::
83
71
84
- // Get tags
85
- const result = await blockBlobClient .getTags ();
72
+ ### [ TypeScript] ( #tab/typescript )
86
73
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" :::
88
75
89
- console .log (` TAG: ${ tag} : ${ result .tags [tag]} ` );
90
- }
91
- }
92
- ```
76
+ ---
93
77
94
78
## Filter and find data with blob index tags
95
79
@@ -113,54 +97,17 @@ To find blobs, create a [BlobClient](storage-blob-javascript-get-started.md#crea
113
97
114
98
- [ BlobServiceClient.findBlobsByTags] ( /javascript/api/@azure/storage-blob/blobserviceclient#@azure-storage-blob-blobserviceclient-findblobsbytags )
115
99
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
+ ---
164
111
165
112
And example output for this function shows the matched blobs and their tags, based on the console.log code in the preceding function:
166
113
@@ -172,6 +119,10 @@ And example output for this function shows the matched blobs and their tags, bas
172
119
173
120
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.
174
121
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
+
175
126
### REST API operations
176
127
177
128
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