Skip to main content

Azure Blob

Credential configuration

To obtain the connection string to Azure Blob, navigate to the main page of the Storage Account you need to access. Next, go to the Access keys section, found in the sidebar inside Security + Networking menu section. In Access keys section you'll find and can copy the connection string to fill in this credential form.

Connection string format example:

DefaultEndpointsProtocol=[http|https];AccountName=myAccountName;AccountKey=myAccountKey

In the extra options field, you can include any of the parameters listed here in the StoragePipelineOptions object.

Here is an example of a filled credential configuration form in YepCode:

Azure Blob Snippets available in YepCode editor

note

The title is the triggering text for YepCode to autocomplete the script.

Integration

New integration from credential
const azureBlobClient = yepcode.integration.azureBlob("credential-slug");
New integration from plain authentication data
const { BlobServiceClient } = require("@azure/storage-blob");

const azureBlobClient = BlobServiceClient.fromConnectionString("your_connection_string");

Create Container

Create container
const containerClient = azureBlobClient.getContainerClient("container-name");

const createContainerResponse = await containerClient.create();
console.log(
`Create container successfully`,
createContainerResponse.requestId
);

List Containers

List containers
let containers = azureBlobClient.listContainers();
for await (const container of containers) {
console.log(`Found container: ${container.name}`);
}

Delete Container

Delete container
const containerClient = azureBlobClient.getContainerClient("container-name");

await containerClient.delete();
console.log(`Deleted container!`);

List Blobs

List blobs
const containerClient = azureBlobClient.getContainerClient("container-name");

let blobs = containerClient.listBlobsFlat();
for await (const blob of blobs) {
console.log(`Found blob: ${blob.name}`);
}

Create Blob from String

Create blob from string
const containerClient = azureBlobClient.getContainerClient("container-name");
const blockBlobClient = containerClient.getBlockBlobClient("blob-name");

const content = "content";
const uploadBlobResponse = await blockBlobClient.upload(
content,
content.length
);
console.log(
`Created block blob successfully`,
uploadBlobResponse.requestId
);

Create Blob from Stream

Create blob from stream
const containerClient = azureBlobClient.getContainerClient("container-name");
const blockBlobClient = containerClient.getBlockBlobClient("blob-name");

await blockBlobClient.uploadStream(stream);
console.log(`Created block blob successfully`);

Read Blob Content

Read blob content
const containerClient = azureBlobClient.getContainerClient("container-name");
const blobClient = containerClient.getBlobClient("blob-name");

const downloadBlockBlobResponse = await blobClient.download();
const blobStream = downloadBlockBlobResponse.readableStreamBody;

blobStream.on("data", (data) => {
console.log(Buffer.from(data).toString("utf8"));
});
blobStream.on("end", () => {
console.log("All blob content shown");
});
blobStream.on("error", (error) => {
console.log(error);
});