Storage
Easily manage blobs, queues, tables, and file shares with the powerful and flexible Azure SDK for JavaScript.
Azure Blob Storage is a cloud object storage solution that stores unstructured data such as text or binary data. It can be accessed from anywhere in the world via HTTP or HTTPS. You can use Blob Storage to serve images or documents directly to a browser, upload files for backup or sharing, stream video and audio, write to log files, store data for backup and restore, disaster recovery, and data archiving.
First, install the necessary package:
npm install @azure/storage-blob
Then, you can start interacting with Blob Storage:
async function uploadFile(blobServiceClient, containerName, blobName, filePath) {
const containerClient = blobServiceClient.getContainerClient(containerName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
await blockBlobClient.uploadFile(filePath, {
blockSizeMax: 4 * 1024 * 1024, // 4MB
});
console.log(`File "${filePath}" uploaded to "${blobName}" in container "${containerName}"`);
}
BlobServiceClient: The primary client for interacting with Blob Storage.ContainerClient: Client for managing containers.BlockBlobClient: Client for managing block blobs.UploadOptions: Options for upload operations.Azure Queue Storage is a service that stores large numbers of messages that can be accessed from anywhere in the world via authenticated HTTP or HTTPS calls. A single queue message can be up to 64 KB in size, and a storage account can contain an unlimited number of queues, up to the limit of the storage account's total capacity.
Install the package:
npm install @azure/storage-queue
Example of adding a message:
async function addMessage(queueServiceClient, queueName, messageText) {
const queueClient = queueServiceClient.getQueueClient(queueName);
await queueClient.sendMessage(messageText);
console.log(`Message "${messageText}" added to queue "${queueName}"`);
}
QueueServiceClient: The client for Queue Storage.QueueClient: Client for managing queues.Azure Table Storage is a NoSQL key-value store that allows you to store large amounts of structured, non-relational data. It's a cost-effective and scalable solution for many types of applications.
Install the package:
npm install @azure/data-tables
Example of inserting an entity:
async function insertEntity(tableClient, entity) {
await tableClient.createEntity(entity);
console.log("Entity inserted successfully.");
}
TableServiceClient: The client for Table Storage.TableClient: Client for managing tables and entities.TableEntity: Represents a record in a table.Azure Files offers fully managed cloud file shares that are accessible via the industry-standard Server Message Block (SMB) protocol. You can mount one or more file shares in the cloud or on-premises, allowing you to lift and shift legacy applications that rely on file shares to Azure.
Install the package:
npm install @azure/storage-file-share
Example of creating a share:
async function createShare(shareServiceClient, shareName) {
await shareServiceClient.createShare(shareName);
console.log(`Share "${shareName}" created.`);
}
ShareServiceClient: Client for managing file shares.ShareClient: Client for interacting with a specific share.ShareDirectoryClient: Client for managing directories.ShareFileClient: Client for managing files.