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() {
// Create Blob Service Client from Account connection string or SAS connection string
// Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net`
// SAS connection string example - `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString`
const STORAGE_CONNECTION_STRING = process.env.STORAGE_CONNECTION_STRING || "";
// Note - Account connection string can only be used in node.
const blobServiceClient = BlobServiceClient.fromConnectionString(STORAGE_CONNECTION_STRING);
// Create a container
console.log("// Create a new container..");
const containerName = `newcontainer${new Date().getTime()}`;
let containerClient = blobServiceClient.getContainerClient(containerName);
let createContainerResponse = await containerClient.create();
console.log(`Created container ${containerName} successfully,`);
console.log(
`requestId - ${createContainerResponse.requestId}, statusCode - ${createContainerResponse._response.status}\n`
);
try {
// Creating an existing container fails...
console.log("// Creating an existing container fails...");
createContainerResponse = await containerClient.create();
export async function main() {
// Create Blob Service Client from Account connection string or SAS connection string
// Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net`
// SAS connection string example - `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString`
const STORAGE_CONNECTION_STRING = process.env.STORAGE_CONNECTION_STRING || "";
// Note - Account connection string can only be used in node.
const blobServiceClient = BlobServiceClient.fromConnectionString(STORAGE_CONNECTION_STRING);
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(`Create container ${containerName} successfully`, createContainerResponse.requestId);
// Delete container
await containerClient.delete();
async function main() {
// Create Blob Service Client from Account connection string or SAS connection string
// Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net`
// SAS connection string example - `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString`
const STORAGE_CONNECTION_STRING = process.env.STORAGE_CONNECTION_STRING || "";
// Note - Account connection string can only be used in node.
const blobServiceClient = BlobServiceClient.fromConnectionString(STORAGE_CONNECTION_STRING);
// Create a container
console.log("// Create a new container..");
const containerName = `newcontainer${new Date().getTime()}`;
let containerClient = blobServiceClient.getContainerClient(containerName);
let createContainerResponse = await containerClient.create();
console.log(`Created container ${containerName} successfully,`);
console.log(
`requestId - ${createContainerResponse.requestId}, statusCode - ${createContainerResponse._response.status}\n`
);
try {
// Creating an existing container fails...
console.log("// Creating an existing container fails...");
createContainerResponse = await containerClient.create();
async function main() {
// Create Blob Service Client from Account connection string or SAS connection string
// Account connection string example - `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net`
// SAS connection string example - `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString`
const STORAGE_CONNECTION_STRING = process.env.STORAGE_CONNECTION_STRING || "";
// Note - Account connection string can only be used in node.
const blobServiceClient = BlobServiceClient.fromConnectionString(STORAGE_CONNECTION_STRING);
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(`Create container ${containerName} successfully`, createContainerResponse.requestId);
// Delete container
await containerClient.delete();
function createBlobClient(
connectionString: string,
containerName: string,
blobName: string
) {
const blobServiceClient = BlobServiceClient.fromConnectionString(
connectionString
);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlobClient(blobName);
return blobClient;
}