Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
// List containers
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
sharedKeyCredential
);
// 1. List Containers
let i = 1;
let iter = await blobServiceClient.listContainers();
for await (const container of iter) {
console.log(`Container ${i++}: ${container.name}`);
}
// 2. Same as the previous example
i = 1;
async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerClient = new ContainerClient(
`https://${account}.blob.core.windows.net/${containerName}`,
sharedKeyCredential
);
const createContainerResponse = await containerClient.create();
console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId);
for (let index = 0; index < 7; index++) {
// Create a blob
const content = "hello";
const blobName = "newblob" + new Date().getTime();
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
export async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerClient = new ContainerClient(
`https://${account}.blob.core.windows.net/${containerName}`,
sharedKeyCredential
);
const createContainerResponse = await containerClient.create();
console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId);
for (let index = 0; index < 7; index++) {
// Create a blob
const content = "hello";
const blobName = "newblob" + new Date().getTime();
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
export async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
// List containers
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
sharedKeyCredential
);
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);
export async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerClient = new ContainerClient(
`https://${account}.blob.core.windows.net/${containerName}`,
sharedKeyCredential
);
const createContainerResponse = await containerClient.create();
console.log(`Create container ${containerName} successfully`, createContainerResponse.requestId);
// Create a blob
const content = "hello";
const blobName = "newblob" + new Date().getTime();
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const uploadBlobResponse = await blockBlobClient.upload(content, content.length);
export async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only avaiable in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerClient = new ContainerClient(
`https://${account}.blob.core.windows.net/${containerName}`,
sharedKeyCredential
);
const createContainerResponse = await containerClient.create();
console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId);
// create some blobs with delimiters in names
const content = "hello";
let blobName = "a1";
let blockBlobClient = containerClient.getBlockBlobClient(blobName);
let uploadBlobResponse = await blockBlobClient.upload(content, content.length);
export async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only avaiable 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()) {
async function main() {
// Enter your storage account name and shared key
const account = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only avaiable 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()) {
async function execute() {
const containerName = "demo";
const blobName = "quickstart.txt";
const content = "Hello Node SDK";
const localFilePath = "../readme.md";
const credentials = new StorageSharedKeyCredential(STORAGE_ACCOUNT_NAME, ACCOUNT_ACCESS_KEY);
const blobServiceClient = new BlobServiceClient(`https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net`,credentials);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlobClient(blobName);
const blockBlobClient = blobClient.getBlockBlobClient();
const aborter = AbortController.timeout(30 * ONE_MINUTE);
await containerClient.create();
console.log(`Container: "${containerName}" is created`);
console.log("Containers:");
await showContainerNames(aborter, blobServiceClient);
await blockBlobClient.upload(content, content.length, aborter);