Skip to content

Commit 5db2521

Browse files
author
Frank Li (Wicresoft North America Ltd)
committed
Remove redundant CreateBlob(), create Blob directly in Blob().
1 parent b00bb81 commit 5db2521

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

3-WebApp-multi-APIs/Controllers/HomeController.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,27 @@ public async Task<IActionResult> Tenants()
7474

7575
public async Task<IActionResult> Blob()
7676
{
77-
string message = await CreateBlob(new TokenAcquisitionTokenCredential(tokenAcquisition));
78-
79-
ViewData["Message"] = message;
80-
return View();
81-
}
82-
83-
private static async Task<string> CreateBlob(TokenAcquisitionTokenCredential tokenCredential)
84-
{
77+
string message = "Blob failed to create";
8578
// replace the URL below with your storage account URL
8679
Uri blobUri = new Uri("https://blobstorageazuread.blob.core.windows.net/sample-container/Blob1.txt");
87-
BlobClient blobClient = new BlobClient(blobUri, tokenCredential);
80+
BlobClient blobClient = new BlobClient(blobUri, new TokenAcquisitionTokenCredential(tokenAcquisition));
8881

8982
string blobContents = "Blob created by Azure AD authenticated user.";
9083
byte[] byteArray = Encoding.ASCII.GetBytes(blobContents);
91-
9284
using (MemoryStream stream = new MemoryStream(byteArray))
9385
{
9486
try
9587
{
9688
await blobClient.UploadAsync(stream);
89+
message = "Blob successfully created";
9790
}
98-
catch (Exception e)
91+
catch (Exception)
9992
{
100-
return ($"Blob failed to create. Exception: {e.Message}");
10193
}
10294
}
103-
return "Blob successfully created";
95+
96+
ViewData["Message"] = message;
97+
return View();
10498
}
10599

106100
[AllowAnonymous]

0 commit comments

Comments
 (0)