Prerequisites:
Task:
- Create container and upload any image.
- Open uploaded image through web browser.
Solution
- Go to Azure Portal.
- Go to Storage Explorer.
- Select storage account you created.
- Right click on Blob containers menu item. Thank select Create blob container option.
- Enter name e.g. images. Select public access level (Blob is enough for this exercise).
- Refresh view. Select created container. Click upload and upload an image.
- Select uploaded blob. Click
Copy URL
button. - Paste url in web browser. Look at you wonderful blob :)
Prerequisites:
- Exercise 1
Task:
- From Azure Portal copy you connection string.
- Paste it into the settings.json file as a value for the "StorageConnectionString" key.
Solution
- Go to Azure Portal.
- Go to Storage accounts. Select you storage account.
- Click the "Access keys" menu item in "Security + networking section".
- Click show keys.
- Cope key1 Connection string value.
- Paste copied string into the settings.json file as a value for the "StorageConnectionString" key.
Prerequisites:
- Exercise 2
Task:
- Implement missing part of the
UploadAsync
method in theAzureBlobService.cs
file
Useful links:
Solution
var blob = blobContainer.GetBlockBlobReference(file.FileName);
using (var stream = file.OpenReadStream())
{
await blob.UploadFromStreamAsync(stream);
}
Prerequisites:
- Exercise 2
Task:
- Implement missing part of the
ListAsync
method in theAzureBlobService.cs
file
Useful links:
Solution
BlobContinuationToken blobContinuationToken = null;
do
{
var response = await blobContainer.ListBlobsSegmentedAsync(blobContinuationToken);
foreach (IListBlobItem blob in response.Results)
{
if (blob.GetType() == typeof(CloudBlockBlob))
allBlobs.Add(blob.Uri);
}
blobContinuationToken = response.ContinuationToken;
} while (blobContinuationToken != null);
Prerequisites:
- Exercise 2
Task:
- Implement missing part of the
DeleteAsync
method in theAzureBlobService.cs
file
Useful links:
Solution
Uri uri = new Uri(fileUri);
string filename = Path.GetFileName(uri.LocalPath);
var blob = blobContainer.GetBlockBlobReference(filename);
await blob.DeleteIfExistsAsync();
Prerequisites:
- Exercise 2
Task:
- Implement missing part of the
DeleteAllAsync
method in theAzureBlobService.cs
file
Useful links:
Solution
BlobContinuationToken blobContinuationToken = null;
do
{
var response = await blobContainer.ListBlobsSegmentedAsync(blobContinuationToken);
foreach (IListBlobItem blob in response.Results)
{
if (blob.GetType() == typeof(CloudBlockBlob))
await((CloudBlockBlob)blob).DeleteIfExistsAsync();
}
blobContinuationToken = response.ContinuationToken;
} while (blobContinuationToken != null);
- Go to
AzureBlobLearning/AzureBlobLearning/AzureBlobLearning
. - Run
dotnet build
. - Run
dotnet run
. - In web browser open the https://localhost:5001