Skip to main content

Azure Blob

With this integration you can store and access data into Azure Blob Storage.

Credential configuration

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

Connection string format example:

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

In the extra options field you can pass any of the params you can find here in the StoragePipelineOptions object.

Here you have 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);
});