Skip to content

Azure Blob Utility (azureBlob.ts)

The Azure Blob utility provides functions for interacting with Azure Blob Storage for document and asset management.

Overview

lib/azureBlob.ts implements Azure Blob Storage operations for file handling and storage management.

Features

  • File upload
  • File download
  • Blob management
  • Access control
  • Error handling
  • Progress tracking

API Reference

Upload Functions

async function uploadFile(file: File, container: string): Promise<string>
async function uploadBlob(data: Blob, name: string): Promise<string>
async function uploadStream(stream: ReadableStream): Promise<string>

Download Functions

async function downloadFile(url: string): Promise<Blob>
async function downloadToStream(url: string): Promise<ReadableStream>
async function getSignedUrl(path: string): Promise<string>

Management Functions

async function deleteBlob(url: string): Promise<void>
async function listBlobs(container: string): Promise<BlobItem[]>
async function getBlobMetadata(url: string): Promise<BlobMetadata>

Integration

Configuration

interface BlobConfig {
  accountName: string;
  containerName: string;
  sasToken: string;
  endpoint: string;
}

Usage Example

const blobService = new BlobService(config);

// Upload file
const url = await blobService.uploadFile(file, 'documents');

// Download file
const blob = await blobService.downloadFile(url);

// Delete file
await blobService.deleteBlob(url);

Error Handling

  1. Error Types
  2. Connection errors
  3. Authentication errors
  4. Storage errors
  5. Quota errors
  6. Permission errors

  7. Recovery

  8. Retry logic
  9. Fallback options
  10. Error reporting
  11. User feedback

Performance

  1. Optimizations
  2. Chunked upload
  3. Stream handling
  4. Cache strategy
  5. Compression

  6. Best Practices

  7. Batch operations
  8. Connection pooling
  9. Resource cleanup
  10. Memory management

Security

  1. Authentication
  2. SAS tokens
  3. Access keys
  4. Role-based access
  5. IP restrictions

  6. Data Protection

  7. Encryption
  8. Secure transfer
  9. Access logging
  10. Audit trails

Notes

  • Connection handling
  • Error recovery
  • Performance tuning
  • Security best practices
  • Resource management