Skip to main content

snippets_js

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);
});