title | titleSuffix | description | services | author | ms.author | ms.date | ms.service | ms.topic | ms.devlang | ms.custom |
---|---|---|---|---|---|---|---|---|---|---|
Download a blob with TypeScript |
Azure Storage |
Learn how to download a blob with TypeScript in Azure Storage by using the client library for JavaScript and TypeScript. |
storage |
pauljewellmsft |
pauljewell |
06/21/2023 |
azure-blob-storage |
how-to |
typescript |
devx-track-ts, devguide-ts, devx-track-js |
[!INCLUDE storage-dev-guide-selector-download]
This article shows how to download a blob using the Azure Storage client library for JavaScript. You can download blob data to various destinations, including a local file path, stream, or text string.
- The examples in this article assume you already have a project set up to work with the Azure Blob Storage client library for JavaScript. To learn about setting up your project, including package installation, importing modules, and creating an authorized client object to work with data resources, see Get started with Azure Blob Storage and TypeScript.
- The authorization mechanism must have permissions to perform a download operation. To learn more, see the authorization guidance for the following REST API operation:
You can use any of the following methods to download a blob:
- BlobClient.download
- BlobClient.downloadToBuffer (only available in Node.js runtime)
- BlobClient.downloadToFile (only available in Node.js runtime)
The following example downloads a blob by using a file path with the BlobClient.downloadToFile method. This method is only available in the Node.js runtime:
:::code language="typescript" source="~/azure_storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-download-to-file.ts" id="snippet_downloadBlobToFile":::
The following example downloads a blob by creating a Node.js writable stream object and then piping to that stream with the BlobClient.download method.
:::code language="typescript" source="~/azure_storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-download-to-stream.ts" id="snippet_downloadBlobAsStream":::
The following Node.js example downloads a blob to a string with BlobClient.download method. In Node.js, blob data returns in a readableStreamBody
.
:::code language="typescript" source="~/azure_storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-download-to-string.ts" id="snippet_downloadBlobToString":::
If you're working with JavaScript in the browser, blob data returns in a promise blobBody. To learn more, see the example usage for browsers at BlobClient.download.
To learn more about how to download blobs using the Azure Blob Storage client library for JavaScript and TypeScript, see the following resources.
The Azure SDK for JavaScript and TypeScript contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar language paradigms. The client library methods for downloading blobs use the following REST API operation:
- Get Blob (REST API)
View code samples from this article (GitHub):
[!INCLUDE storage-dev-guide-resources-typescript]