-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathcustomPipeline.js
More file actions
60 lines (47 loc) · 1.95 KB
/
customPipeline.js
File metadata and controls
60 lines (47 loc) · 1.95 KB
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
57
58
59
60
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @summary use custom HTTP pipeline options when connecting to the service
*/
const {
BlobServiceClient,
StorageSharedKeyCredential,
newPipeline,
} = require("@azure/storage-blob");
// Load the .env file if it exists
require("dotenv/config");
async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "<account name>";
const accountKey = process.env.ACCOUNT_KEY || "<account key>";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only available in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
// Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline
const pipeline = newPipeline(sharedKeyCredential, {
// httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface
retryOptions: { maxTries: 4 }, // Retry options
userAgentOptions: { userAgentPrefix: "Sample V1.0.0" }, // Customized telemetry string
});
// List containers
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
pipeline,
);
let i = 1;
for await (const container of blobServiceClient.listContainers()) {
console.log(`Container ${i++}: ${container.name}`);
}
// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerClient = blobServiceClient.getContainerClient(containerName);
const createContainerResponse = await containerClient.create();
console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId);
// Delete container
await containerClient.delete();
console.log("Deleted container:", containerClient.containerName);
}
main().catch((error) => {
console.error(error);
process.exit(1);
});