Azure Blob Storage

Upload files from the browser directly to Azure Blob Storage with SAS URLs, store metadata in Convex, and serve signed read URLs without the Azure SDK.

Installation

npm install convex-azure-blob-storage

About Azure Blob Storage

Azure Blob Storage for Convex bridges direct browser-to-Azure uploads with Convex-managed file metadata. The component generates short-lived SAS URLs scoped to a single blob, validates uploaded files by size, content type, and magic bytes before serving, and stores status, uploader identity, and custom metadata in a reactive Convex table. SAS token signing uses Web Crypto, so no Azure SDK is required and everything runs in the standard Convex runtime without `"use node"`.

Benefits

Use cases

how to upload files to Azure Blob Storage from a React app with Convex

convex-azure-blob-storage provides a useUploadFile React hook that calls a generateUploadUrl function to get a short-lived SAS URL, PUTs the file directly to Azure with progress events, then calls confirmUpload to record the metadata in Convex. The file bytes never pass through your Convex functions. The hook returns upload, progress, isUploading, error, and cancel.

generate Azure SAS URL in Convex without Node.js runtime

convex-azure-blob-storage signs SAS tokens using the Web Crypto API, so it runs in the default Convex runtime without requiring use node. It supports both shared account key signing and Microsoft Entra user-delegation SAS for environments where shared key access is disabled.

how to run a callback when a file upload is confirmed in Convex

The clientApi method accepts an onUpload option pointing to an internal Convex mutation. That mutation is committed in the same transaction as the file becoming ready, so if it throws, both the file status change and the attachment roll back. Inside the mutation you can call azure.getFile to read the confirmed file and update your app tables.

how to delete uploaded blobs and clean up abandoned uploads in Convex

convex-azure-blob-storage includes a sweep cron job that deletes blobs for uploads that were never confirmed and retries deletes that previously failed. You schedule it hourly in convex/crons.ts and export the sweep action from your files module. Deletion is transactional with your own data.

Frequently asked questions

Does convex-azure-blob-storage require the Azure SDK or the Node.js runtime?

No. convex-azure-blob-storage signs SAS tokens using the Web Crypto API built into the default Convex runtime, so you do not need to add the Azure SDK as a dependency and you do not need to annotate functions with use node. This keeps bundle size small and avoids Node.js cold start penalties.

How does convex-azure-blob-storage prevent unauthorized or malicious uploads?

Each SAS URL issued by convex-azure-blob-storage is valid for five minutes, allows only a single server-named blob, and only permits create operations. After the browser finishes uploading, confirmUpload checks the file size, content type, and leading bytes against the declared values before the file is marked ready. Files that fail validation are deleted. You control who may upload by implementing the identify callback, which returns null to refuse a request.

What Convex version is required to use convex-azure-blob-storage?

convex-azure-blob-storage requires convex version 1.46 or later. You register it as a Convex component in convex/convex.config.ts using app.use(azureBlobStorage) after importing from convex-azure-blob-storage/convex.config.js.

Does convex-azure-blob-storage support Microsoft Entra in addition to shared account keys?

Yes. convex-azure-blob-storage supports both shared account key signing and Microsoft Entra user-delegation SAS. When AZURE_BLOB_KEY is unset you configure AZURE_BLOB_TENANT_ID, AZURE_BLOB_CLIENT_ID, and AZURE_BLOB_CLIENT_SECRET instead. Entra mode requires an additional hourly cron job called refreshUserDelegationKey to renew the 24-hour signing key before it expires.

How are files served after upload with convex-azure-blob-storage?

convex-azure-blob-storage generates cacheable, signed read URLs that are valid for a configurable time window. The URLs can force a file download under the original file name or include Cache-Control headers. You can also configure a CDN or a public container by setting AZURE_PUBLIC_BASE_URL, in which case reads are served as a plain base URL plus the blob name without a token.

Links

Components

Open-source building blocks for your Convex app

Browse components in this category.

Loading components