-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathlist-files.js
56 lines (47 loc) · 1.55 KB
/
list-files.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// [SNIPPET_REGISTRY disabled]
// [SNIPPETS_SEPARATION enabled]
function listAll() {
// [START storage_list_all]
const { getStorage, ref, listAll } = require("firebase/storage");
const storage = getStorage();
// Create a reference under which you want to list
const listRef = ref(storage, 'files/uid');
// Find all the prefixes and items.
listAll(listRef)
.then((res) => {
res.prefixes.forEach((folderRef) => {
// All the prefixes under listRef.
// You may call listAll() recursively on them.
});
res.items.forEach((itemRef) => {
// All the items under listRef.
});
}).catch((error) => {
// Uh-oh, an error occurred!
});
// [END storage_list_all]
}
function listPaginate() {
// [START storage_list_paginate]
const { getStorage, ref, list } = require("firebase/storage");
async function pageTokenExample(){
// Create a reference under which you want to list
const storage = getStorage();
const listRef = ref(storage, 'files/uid');
// Fetch the first page of 100.
const firstPage = await list(listRef, { maxResults: 100 });
// Use the result.
// processItems(firstPage.items)
// processPrefixes(firstPage.prefixes)
// Fetch the second page if there are more elements.
if (firstPage.nextPageToken) {
const secondPage = await list(listRef, {
maxResults: 100,
pageToken: firstPage.nextPageToken,
});
// processItems(secondPage.items)
// processPrefixes(secondPage.prefixes)
}
}
// [END storage_list_paginate]
}