You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 operations:
- Packages installed to your project directory. These examples use **Azure.Storage.Blobs**. If you're using `DefaultAzureCredential` for authorization, you also need **Azure.Identity**. 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
+
## About downloading blobs
31
+
32
+
The [Get Blob](/rest/api/storageservices/put-blob) operation reads or downloads a blob from Azure Storage, including its metadata and properties. To learn more about the `Get Blob` operation, including timeout parameters and error conditions, see [Get Blob remarks](/rest/api/storageservices/get-blob#remarks).
33
+
34
+
## Download a blob
35
+
36
+
You can download a blob by using any of the following methods:
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:
43
+
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:
> 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.
33
47
34
48
## Download to a file path
35
49
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.
// 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.
50
+
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.
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.
// Let the user know that the directory does not exist
71
-
Console.WriteLine($"Directory not found: {ex.Message}");
72
-
}
73
-
}
74
-
```
56
+
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).
-[View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/dotnet/BlobDevGuideBlobs/DownloadBlob.cs)
0 commit comments