@@ -18,12 +18,12 @@ cargo add azure_storage_blob
1818
1919*  You must have an [ Azure subscription]  and an [ Azure storage account]  to use this package.
2020
21- 
22- 
2321### Create a storage account  
22+ 
2423If you wish to create a new storage account, you can use the
2524[ Azure Portal] , [ Azure PowerShell] , or [ Azure CLI] :
26- ``` bash 
25+ 
26+ ``` sh 
2727#  Create a new resource group to hold the storage account -
2828#  if using an existing resource group, skip this step
2929az group create --name my-resource-group --location westus2
@@ -35,85 +35,109 @@ az storage account create -n my-storage-account-name -g my-resource-group
3535#### Authenticate the client  
3636
3737In order to interact with the Azure Blob Storage service, you'll need to create an instance of a client, ` BlobClient ` , ` BlobContainerClient ` , or ` BlobServiceClient ` . The [ Azure Identity]  library makes it easy to add Microsoft Entra ID support for authenticating Azure SDK clients with their corresponding Azure services:
38- ``` rust 
39- use  azure_storage_blob :: BlobClient ;
38+ 
39+ ``` rust  no_run
40+ use  azure_storage_blob :: {BlobClient , BlobClientOptions };
4041use  azure_identity :: DefaultAzureCredential ;
4142
42- //  Create a BlobClient that will authenticate through Microsoft Entra ID
43- let  credential  =  DefaultAzureCredential :: new ()? ;
44- let  blob_client  =  BlobClient :: new (
45-     " https://<storage_account_name>.blob.core.windows.net/"  , //  endpoint
46-     " container_name" . to_string (),                            //  container name
47-     " blob_name" . to_string (),                                 //  blob name
48-     credential ,                                              //  credential
49-     Some (BlobClientOptions :: default ()),                      //  BlobClient options
50- )? ;
43+ #[tokio:: main]
44+ async  fn  main () ->  Result <(), Box <dyn  std :: error :: Error >> {
45+     //  Create a BlobClient that will authenticate through Microsoft Entra ID
46+     let  credential  =  DefaultAzureCredential :: new ()? ;
47+     let  blob_client  =  BlobClient :: new (
48+         " https://<storage_account_name>.blob.core.windows.net/"  , //  endpoint
49+         " container_name" . to_string (),                            //  container name
50+         " blob_name" . to_string (),                                 //  blob name
51+         credential ,                                              //  credential
52+         Some (BlobClientOptions :: default ()),                      //  BlobClient options
53+     )? ;
54+     Ok (())
55+ }
5156``` 
5257
5358#### Permissions  
59+ 
5460You may need to specify RBAC roles to access Blob Storage via Microsoft Entra ID. Please see [ Assign an Azure role for access to blob data]  for more details.
5561
5662## Examples  
5763
5864### Create ` BlobClient `   
59- ``` rust 
60- use  azure_storage_blob :: BlobClient ;
65+ 
66+ ``` rust  no_run
67+ use  azure_storage_blob :: {BlobClient , BlobClientOptions };
6168use  azure_identity :: DefaultAzureCredential ;
6269
63- //  Create a BlobClient that will authenticate through Microsoft Entra ID
64- let  credential  =  DefaultAzureCredential :: new ()? ;
65- let  blob_client  =  BlobClient :: new (
66-     " https://<storage_account_name>.blob.core.windows.net/"  , //  endpoint
67-     " container_name" . to_string (),                            //  container name
68-     " blob_name" . to_string (),                                 //  blob name
69-     credential ,                                              //  credential
70-     Some (BlobClientOptions :: default ()),                      //  BlobClient options
71- )? ;
70+ #[tokio:: main]
71+ async  fn  main () ->  Result <(), Box <dyn  std :: error :: Error >> {
72+     //  Create a BlobClient that will authenticate through Microsoft Entra ID
73+     let  credential  =  DefaultAzureCredential :: new ()? ;
74+     let  blob_client  =  BlobClient :: new (
75+         " https://<storage_account_name>.blob.core.windows.net/"  , //  endpoint
76+         " container_name" . to_string (),                            //  container name
77+         " blob_name" . to_string (),                                 //  blob name
78+         credential ,                                              //  credential
79+         Some (BlobClientOptions :: default ()),                      //  BlobClient options
80+     )? ;
81+     Ok (())
82+ }
7283``` 
84+ 
7385### Upload Blob  
74- ``` rust 
75- use  azure_storage_blob :: BlobClient ;
86+ 
87+ ``` rust  no_run
88+ use  azure_core :: http :: RequestContent ;
89+ use  azure_storage_blob :: {BlobClient , BlobClientOptions };
7690use  azure_identity :: DefaultAzureCredential ;
7791
78- let  credential  =  DefaultAzureCredential :: new ()? ;
79- let  blob_client  =  BlobClient :: new (
80-     " https://<storage_account_name>.blob.core.windows.net/"  ,
81-     " container_name" . to_string (),
82-     " blob_name" . to_string (),
83-     credential ,
84-     Some (BlobClientOptions :: default ()),
85- )? ;
86- 
87- blob_client 
88-     . upload (
89-         RequestContent :: from (data . to_vec ()), //  data
90-         false ,                               //  overwrite
91-         u64 :: try_from (data . len ())? ,          //  content length
92-         None ,                                //  upload options
93-     )
94-     . await ? ;
92+ #[tokio:: main]
93+ async  fn  main () ->  Result <(), Box <dyn  std :: error :: Error >> {
94+     let  credential  =  DefaultAzureCredential :: new ()? ;
95+     let  blob_client  =  BlobClient :: new (
96+         " https://<storage_account_name>.blob.core.windows.net/"  ,
97+         " container_name" . to_string (),
98+         " blob_name" . to_string (),
99+         credential ,
100+         Some (BlobClientOptions :: default ()),
101+     )? ;
102+ 
103+     let  data  =  b " hello world"  ;
104+     blob_client 
105+         . upload (
106+             RequestContent :: from (data . to_vec ()), //  data
107+             false ,                               //  overwrite
108+             u64 :: try_from (data . len ())? ,          //  content length
109+             None ,                                //  upload options
110+         )
111+         . await ? ;
112+     Ok (())
113+ }
95114``` 
96115
97116### Get Blob Properties  
98- ``` rust 
99- use  azure_storage_blob :: BlobClient ;
117+ 
118+ ``` rust  no_run
119+ use  azure_storage_blob :: {BlobClient , BlobClientOptions };
100120use  azure_identity :: DefaultAzureCredential ;
101121
102- let  credential  =  DefaultAzureCredential :: new ()? ;
103- let  blob_client  =  BlobClient :: new (
104-     " https://<storage_account_name>.blob.core.windows.net/"  ,
105-     " container_name" . to_string (),
106-     " blob_name" . to_string (),
107-     credential ,
108-     Some (BlobClientOptions :: default ()),
109- )? ;
110- let  blob_properties  =  blob_client . get_properties (
111-     None  //  get properties options
112-     )
113-     . await ? ;
122+ #[tokio:: main]
123+ async  fn  main () ->  Result <(), Box <dyn  std :: error :: Error >> {
124+ 
125+     let  credential  =  DefaultAzureCredential :: new ()? ;
126+     let  blob_client  =  BlobClient :: new (
127+         " https://<storage_account_name>.blob.core.windows.net/"  ,
128+         " container_name" . to_string (),
129+         " blob_name" . to_string (),
130+         credential ,
131+         Some (BlobClientOptions :: default ()),
132+     )? ;
133+     let  blob_properties  =  blob_client . get_properties (
134+         None  //  get properties options
135+         )
136+         . await ? ;
137+     Ok (())
138+ }
114139``` 
115140
116- 
117141## Next steps  
118142
119143### Provide feedback  
@@ -138,7 +162,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
138162[ Azure Identity ] : https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/identity/azure_identity 
139163[ API reference documentation ] : https://docs.rs/crate/azure_storage_blob/latest 
140164[ Package (crates.io) ] : https://crates.io/crates/azure_storage_blob 
141- [ Source code ] : https://github.com/Azure/azure-sdk-for-python /tree/main/sdk/storage/azure-storage-blob  
165+ [ Source code ] : https://github.com/Azure/azure-sdk-for-rust /tree/main/sdk/storage/azure_storage_blob  
142166[ REST API documentation ] : https://learn.microsoft.com/rest/api/storageservices/blob-service-rest-api 
143167[ Product documentation ] : https://learn.microsoft.com/azure/storage/blobs/storage-blobs-overview 
144168[ Assign an Azure role for access to blob data ] : https://learn.microsoft.com/azure/storage/blobs/assign-azure-role-data-access?tabs=portal 
0 commit comments