Skip to content

Commit 29778c7

Browse files
authored
Merge pull request #235413 from pauljewellmsft/pauljewell-upload-download
Update dev guide upload/download articles
2 parents 37f1f63 + 1a610b4 commit 29778c7

11 files changed

+243
-328
lines changed

articles/storage/blobs/storage-blob-download-java.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,40 @@ ms.custom: devx-track-java, devguide-java
1616

1717
# Download a blob with Java
1818

19-
This article shows how to download a blob using the [Azure Storage client library for Java](/java/api/overview/azure/storage-blob-readme). You can download a blob by using any of the following methods:
19+
This article shows how to download a blob using the [Azure Storage client library for Java](/java/api/overview/azure/storage-blob-readme). You can download blob data to various destinations, including a local file path, stream, or text string. You can also open a blob stream and read from it.
20+
21+
## Prerequisites
22+
23+
To work with the code examples in this article, make sure you have:
24+
25+
- An authorized client object to connect to Blob Storage data resources. To learn more, see [Create and manage client objects that interact with data resources](storage-blob-client-management.md).
26+
- Permissions to perform an upload operation. To learn more, see the authorization guidance for the following REST API operation:
27+
- [Get Blob](/rest/api/storageservices/get-blob#authorization)
28+
- The package **azure-storage-blob** installed to your project directory. To learn more about setting up your project, see [Get Started with Azure Storage and Java](storage-blob-java-get-started.md#set-up-your-project).
29+
30+
## Download a blob
31+
32+
You can use any of the following methods to download a blob:
2033

2134
- [downloadContent](/java/api/com.azure.storage.blob.specialized.blobclientbase)
2235
- [downloadStream](/java/api/com.azure.storage.blob.specialized.blobclientbase)
2336
- [downloadToFile](/java/api/com.azure.storage.blob.specialized.blobclientbase)
2437

2538
## Download to a file path
2639

27-
The following example downloads a blob by using a file path:
40+
The following example downloads a blob to a local file path:
2841

2942
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobDownload.java" id="Snippet_DownloadBLobFile":::
3043

3144
## Download to a stream
3245

33-
The following example downloads a blob to an `OutputStream`:
46+
The following example downloads a blob to an `OutputStream` object:
3447

3548
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobDownload.java" id="Snippet_DownloadBLobStream":::
3649

3750
## Download to a string
3851

39-
The following example downloads a blob to a `String` object. This example assumes that the blob is a text file.
52+
The following example assumes that the blob is a text file, and downloads the blob to a `String` object:
4053

4154
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobDownload.java" id="Snippet_DownloadBLobText":::
4255

articles/storage/blobs/storage-blob-download-javascript.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: storage
66
author: pauljewellmsft
77

88
ms.author: pauljewell
9-
ms.date: 11/30/2022
9+
ms.date: 04/21/2023
1010
ms.service: storage
1111
ms.subservice: blobs
1212
ms.topic: how-to
@@ -16,14 +16,24 @@ ms.custom: devx-track-js, devguide-js
1616

1717
# Download a blob with JavaScript
1818

19-
This article shows how to download a blob using the [Azure Storage client library for JavaScript](https://www.npmjs.com/package/@azure/storage-blob). You can download a blob by using any of the following methods:
19+
This article shows how to download a blob using the [Azure Storage client library for JavaScript](https://www.npmjs.com/package/@azure/storage-blob). You can download blob data to various destinations, including a local file path, stream, or text string.
20+
21+
## Prerequisites
22+
23+
To work with the code examples in this article, make sure you have:
24+
25+
- An authorized client object to connect to Blob Storage data resources. To learn more, see [Create and manage client objects that interact with data resources](storage-blob-client-management.md).
26+
- Permissions to perform an upload operation. To learn more, see the authorization guidance for the following REST API operation:
27+
- [Get Blob](/rest/api/storageservices/get-blob#authorization)
28+
- The package **@azure/storage-blob** installed to your project directory. To learn more about setting up your project, see [Get started with Azure Blob Storage and JavaScript](storage-blob-javascript-get-started.md).
29+
30+
## Download a blob
31+
32+
You can use any of the following methods to download a blob:
2033

2134
- [BlobClient.download](/javascript/api/@azure/storage-blob/blobclient#@azure-storage-blob-blobclient-download)
2235
- [BlobClient.downloadToBuffer](/javascript/api/@azure/storage-blob/blobclient#@azure-storage-blob-blobclient-downloadtobuffer-1) (only available in Node.js runtime)
2336
- [BlobClient.downloadToFile](/javascript/api/@azure/storage-blob/blobclient#@azure-storage-blob-blobclient-downloadtofile) (only available in Node.js runtime)
24-
25-
> [!NOTE]
26-
> The examples in this article assume that you've created a [BlobServiceClient](/javascript/api/@azure/storage-blob/blobserviceclient) object by using the guidance in the [Get started with Azure Blob Storage and JavaScript](storage-blob-javascript-get-started.md) article. Blobs in Azure Storage are organized into containers. Before you can upload a blob, you must first create a container. To learn how to create a container, see [Create a container in Azure Storage with JavaScript](storage-blob-container-create.md).
2737

2838
## Download to a file path
2939

articles/storage/blobs/storage-blob-download-python.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: storage
66
author: pauljewellmsft
77

88
ms.author: pauljewell
9-
ms.date: 01/24/2023
9+
ms.date: 04/21/2023
1010
ms.service: storage
1111
ms.subservice: blobs
1212
ms.topic: how-to
@@ -16,7 +16,20 @@ ms.custom: devx-track-python, devguide-python
1616

1717
# Download a blob with Python
1818

19-
This article shows how to download a blob using the [Azure Storage client library for Python](/python/api/overview/azure/storage). You can download a blob by using the following method:
19+
This article shows how to download a blob using the [Azure Storage client library for Python](/python/api/overview/azure/storage). You can download blob data to various destinations, including a local file path, stream, or text string. You can also open a blob stream and read from it.
20+
21+
## Prerequisites
22+
23+
To work with the code examples in this article, make sure you have:
24+
25+
- An authorized client object to connect to Blob Storage data resources. To learn more, see [Create and manage client objects that interact with data resources](storage-blob-client-management.md).
26+
- Permissions to perform an upload operation. To learn more, see the authorization guidance for the following REST API operation:
27+
- [Get Blob](/rest/api/storageservices/get-blob#authorization)
28+
- The package **azure-storage-blob** installed to your project directory. To learn more about setting up your project, see [Get Started with Azure Storage and Java](storage-blob-java-get-started.md#set-up-your-project).
29+
30+
## Download a blob
31+
32+
You can use the following method to download a blob:
2033

2134
- [BlobClient.download_blob](/python/api/azure-storage-blob/azure.storage.blob.blobclient#azure-storage-blob-blobclient-download-blob)
2235

articles/storage/blobs/storage-blob-download-typescript.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: storage
66
author: pauljewellmsft
77

88
ms.author: pauljewell
9-
ms.date: 03/21/2023
9+
ms.date: 04/21/2023
1010
ms.service: storage
1111
ms.subservice: blobs
1212
ms.topic: how-to
@@ -16,14 +16,24 @@ ms.custom: devx-track-ts, devguide-ts
1616

1717
# Download a blob with TypeScript
1818

19-
This article shows how to download a blob using the [Azure Storage client library for JavaScript](https://www.npmjs.com/package/@azure/storage-blob). You can download a blob by using any of the following methods:
19+
This article shows how to download a blob using the [Azure Storage client library for JavaScript](https://www.npmjs.com/package/@azure/storage-blob). You can download blob data to various destinations, including a local file path, stream, or text string.
20+
21+
## Prerequisites
22+
23+
To work with the code examples in this article, make sure you have:
24+
25+
- An authorized client object to connect to Blob Storage data resources. To learn more, see [Create and manage client objects that interact with data resources](storage-blob-client-management.md).
26+
- Permissions to perform an upload operation. To learn more, see the authorization guidance for the following REST API operation:
27+
- [Get Blob](/rest/api/storageservices/get-blob#authorization)
28+
- The package **@azure/storage-blob** installed to your project directory. To learn more about setting up your project, see [Get started with Azure Blob Storage and TypeScript](storage-blob-typescript-get-started.md).
29+
30+
## Download a blob
31+
32+
You can use any of the following methods to download a blob:
2033

2134
- [BlobClient.download](/javascript/api/@azure/storage-blob/blobclient#@azure-storage-blob-blobclient-download)
2235
- [BlobClient.downloadToBuffer](/javascript/api/@azure/storage-blob/blobclient#@azure-storage-blob-blobclient-downloadtobuffer-1) (only available in Node.js runtime)
2336
- [BlobClient.downloadToFile](/javascript/api/@azure/storage-blob/blobclient#@azure-storage-blob-blobclient-downloadtofile) (only available in Node.js runtime)
24-
25-
> [!NOTE]
26-
> The examples in this article assume that you've created a [BlobServiceClient](/javascript/api/@azure/storage-blob/blobserviceclient) object by using the guidance in the [Get started with Azure Blob Storage and TypeScript](storage-blob-typescript-get-started.md) article. Blobs in Azure Storage are organized into containers. Before you can upload a blob, you must first create a container. To learn how to create a container, see [Create a container in Azure Storage with TypeScript](storage-blob-container-create-typescript.md).
2737

2838
## Download to a file path
2939

articles/storage/blobs/storage-blob-download.md

Lines changed: 34 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: storage
66
author: pauljewellmsft
77

88
ms.author: pauljewell
9-
ms.date: 03/28/2022
9+
ms.date: 04/21/2023
1010
ms.service: storage
1111
ms.subservice: blobs
1212
ms.topic: how-to
@@ -16,91 +16,54 @@ ms.custom: devx-track-csharp, devguide-csharp
1616

1717
# Download a blob with .NET
1818

19-
This article shows how to download a blob using the [Azure Storage client library for .NET](/dotnet/api/overview/azure/storage). You can download a blob by using any of the following methods:
19+
This article shows how to download a blob using the [Azure Storage client library for .NET](/dotnet/api/overview/azure/storage). You can download blob data to various destinations, including a local file path, stream, or text string. You can also open a blob stream and read from it.
20+
21+
## Prerequisites
22+
23+
To work with the code examples in this article, make sure you have:
24+
25+
- An authorized client object to connect to Blob Storage data resources. To learn more, see [Create and manage client objects that interact with data resources](storage-blob-client-management.md).
26+
- Permissions to perform an upload operation. To learn more, see the authorization guidance for the following REST API operation:
27+
- [Get Blob](/rest/api/storageservices/get-blob#authorization)
28+
- The package **Azure.Storage.Blobs** installed to your project directory. To learn more about setting up your project, see [Get Started with Azure Storage and .NET](storage-blob-dotnet-get-started.md#set-up-your-project).
29+
30+
## Download a blob
31+
32+
You can use any of the following methods to download a blob:
2033

2134
- [DownloadTo](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.downloadto)
2235
- [DownloadToAsync](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.downloadtoasync)
2336
- [DownloadContent](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.downloadcontent)
2437
- [DownloadContentAsync](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.downloadcontentasync)
2538

26-
You can also open a stream to read from a blob. The stream will only download the blob as the stream is read from. Use either of the following methods:
39+
You can also open a stream to read from a blob. The stream only downloads the blob as the stream is read from. You can use either of the following methods:
2740

2841
- [OpenRead](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.openread)
2942
- [OpenReadAsync](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.openreadasync)
30-
31-
> [!NOTE]
32-
> The examples in this article assume that you've created a [BlobServiceClient](/dotnet/api/azure.storage.blobs.blobserviceclient) object by using the guidance in the [Get started with Azure Blob Storage and .NET](storage-blob-dotnet-get-started.md) article.
3343

3444
## Download to a file path
3545

36-
The following example downloads a blob by using a file path. If the specified directory does not exist, handle the exception and notify the user.
37-
38-
```csharp
39-
public static async Task DownloadBlob(BlobClient blobClient, string localFilePath)
40-
{
41-
try
42-
{
43-
await blobClient.DownloadToAsync(localFilePath);
44-
}
45-
catch (DirectoryNotFoundException ex)
46-
{
47-
// Let the user know that the directory does not exist
48-
Console.WriteLine($"Directory not found: {ex.Message}");
49-
}
50-
}
51-
```
52-
53-
If the file already exists at `localFilePath`, it will be overwritten by default during subsequent downloads.
46+
The following example downloads a blob to a local file path. If the specified directory doesn't exist, the code throws a [DirectoryNotFoundException](/dotnet/api/system.io.directorynotfoundexception). If the file already exists at `localFilePath`, it's overwritten by default during subsequent downloads.
47+
48+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/DownloadBlob.cs" id="Snippet_DownloadBlobToFile":::
5449

5550
## Download to a stream
5651

57-
The following example downloads a blob by creating a [Stream](/dotnet/api/system.io.stream) object and then downloads to that stream. If the specified directory does not exist, handle the exception and notify the user.
58-
59-
```csharp
60-
public static async Task DownloadToStream(BlobClient blobClient, string localFilePath)
61-
{
62-
try
63-
{
64-
FileStream fileStream = File.OpenWrite(localFilePath);
65-
await blobClient.DownloadToAsync(fileStream);
66-
fileStream.Close();
67-
}
68-
catch (DirectoryNotFoundException ex)
69-
{
70-
// Let the user know that the directory does not exist
71-
Console.WriteLine($"Directory not found: {ex.Message}");
72-
}
73-
}
74-
```
52+
The following example downloads a blob by creating a [Stream](/dotnet/api/system.io.stream) object and then downloads to that stream. If the specified directory doesn't exist, the code throws a [DirectoryNotFoundException](/dotnet/api/system.io.directorynotfoundexception).
53+
54+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/DownloadBlob.cs" id="Snippet_DownloadBlobToStream":::
7555

7656
## Download to a string
7757

78-
The following example downloads a blob to a string. This example assumes that the blob is a text file.
58+
The following example assumes that the blob is a text file, and downloads the blob to a string:
7959

80-
```csharp
81-
public static async Task DownloadToText(BlobClient blobClient)
82-
{
83-
BlobDownloadResult downloadResult = await blobClient.DownloadContentAsync();
84-
string downloadedData = downloadResult.Content.ToString();
85-
Console.WriteLine("Downloaded data:", downloadedData);
86-
}
87-
```
60+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/DownloadBlob.cs" id="Snippet_DownloadBlobToString":::
8861

8962
## Download from a stream
9063

91-
The following example downloads a blob by reading from a stream.
92-
93-
```csharp
94-
public static async Task DownloadfromStream(BlobClient blobClient, string localFilePath)
95-
{
96-
using (var stream = await blobClient.OpenReadAsync())
97-
{
98-
FileStream fileStream = File.OpenWrite(localFilePath);
99-
await stream.CopyToAsync(fileStream);
100-
}
101-
}
64+
The following example downloads a blob by reading from a stream:
10265

103-
```
66+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/DownloadBlob.cs" id="Snippet_DownloadBlobFromStream":::
10467

10568
## Resources
10669

@@ -112,4 +75,12 @@ The Azure SDK for .NET contains libraries that build on top of the Azure REST AP
11275

11376
- [Get Blob](/rest/api/storageservices/get-blob) (REST API)
11477

78+
### Code samples
79+
80+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/dotnet/BlobDevGuideBlobs/DownloadBlob.cs)
81+
11582
[!INCLUDE [storage-dev-guide-resources-dotnet](../../../includes/storage-dev-guides/storage-dev-guide-resources-dotnet.md)]
83+
84+
### See also
85+
86+
- [Performance tuning for uploads and downloads](storage-blobs-tune-upload-download.md).

0 commit comments

Comments
 (0)