Skip to content

Commit 1f49b1d

Browse files
authored
Merge pull request #221776 from pauljewellmsft/pauljewell-js-sample
Update code sample and output
2 parents f15bb86 + 0d01801 commit 1f49b1d

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

articles/storage/blobs/storage-blobs-list-javascript.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ async function listBlobsFlatWithPageMarker(containerClient) {
8888

8989
// some options for filtering list
9090
const listOptions = {
91-
includeMetadata: true,
91+
includeMetadata: false,
9292
includeSnapshots: false,
93-
includeTags: true,
93+
includeTags: false,
9494
includeVersions: false,
9595
prefix: ''
9696
};
@@ -123,9 +123,12 @@ async function listBlobsFlatWithPageMarker(containerClient) {
123123
The sample output is similar to:
124124

125125
```console
126-
Flat listing: 1: a0/blob-0.txt
127-
Flat listing: 2: a1/blob-1.txt
128-
Flat listing: 3: a2/blob-2.txt
126+
Flat listing: 1: a1
127+
Flat listing: 2: a2
128+
Flat listing: 3: folder1/b1
129+
Flat listing: 4: folder1/b2
130+
Flat listing: 5: folder2/sub1/c
131+
Flat listing: 6: folder2/sub1/d
129132
```
130133

131134
## Use a hierarchical listing
@@ -138,25 +141,27 @@ The following example lists the blobs in the specified container using a hierarc
138141

139142
```javascript
140143
// Recursively list virtual folders and blobs
141-
async function listBlobHierarchical(containerClient, virtualHierarchyDelimiter='/') {
144+
// Pass an empty string for prefixStr to list everything in the container
145+
async function listBlobHierarchical(containerClient, prefixStr) {
142146

143147
// page size - artificially low as example
144148
const maxPageSize = 2;
145149

146150
// some options for filtering list
147151
const listOptions = {
148-
includeMetadata: true,
152+
includeMetadata: false,
149153
includeSnapshots: false,
150-
includeTags: true,
154+
includeTags: false,
151155
includeVersions: false,
152-
prefix: ''
156+
prefix: prefixStr
153157
};
154158

159+
let delimiter = '/';
155160
let i = 1;
156-
console.log(`Folder ${virtualHierarchyDelimiter}`);
161+
console.log(`Folder ${delimiter}${prefixStr}`);
157162

158163
for await (const response of containerClient
159-
.listBlobsByHierarchy(virtualHierarchyDelimiter, listOptions)
164+
.listBlobsByHierarchy(delimiter, listOptions)
160165
.byPage({ maxPageSize })) {
161166

162167
console.log(` Page ${i++}`);
@@ -166,9 +171,8 @@ async function listBlobHierarchical(containerClient, virtualHierarchyDelimiter='
166171

167172
// Do something with each virtual folder
168173
for await (const prefix of segment.blobPrefixes) {
169-
170-
// build new virtualHierarchyDelimiter from current and next
171-
await listBlobHierarchical(containerClient, `${virtualHierarchyDelimiter}${prefix.name}`);
174+
// build new prefix from current virtual folder
175+
await listBlobHierarchical(containerClient, prefix.name);
172176
}
173177
}
174178

@@ -184,27 +188,23 @@ async function listBlobHierarchical(containerClient, virtualHierarchyDelimiter='
184188
The sample output is similar to:
185189

186190
```console
187-
Hier listing: Folder /
188-
Page 1
189-
Hier listing: Folder /a0/
191+
Folder /
190192
Page 1
191-
BlobItem: name - a0/blob-0.txt
192-
BlobItem: name - a1/blob-1.txt
193+
BlobItem: name - a1
194+
BlobItem: name - a2
193195
Page 2
194-
BlobItem: name - a2/blob-2.txt
195-
Hier listing: Folder /a1/
196+
Folder /folder1/
196197
Page 1
197-
BlobItem: name - a0/blob-0.txt
198-
BlobItem: name - a1/blob-1.txt
199-
Page 2
200-
BlobItem: name - a2/blob-2.txt
201-
Page 2
202-
Hier listing: Folder /a2/
198+
BlobItem: name - folder1/b1
199+
BlobItem: name - folder1/b2
200+
Folder /folder2/
201+
Page 1
202+
Folder /folder2/sub1/
203203
Page 1
204-
BlobItem: name - a0/blob-0.txt
205-
BlobItem: name - a1/blob-1.txt
204+
BlobItem: name - folder2/sub1/c
205+
BlobItem: name - folder2/sub1/d
206206
Page 2
207-
BlobItem: name - a2/blob-2.txt
207+
BlobItem: name - folder2/sub1/e
208208
```
209209

210210
> [!NOTE]

0 commit comments

Comments
 (0)