Skip to content

Commit 1130984

Browse files
committed
Corrected package versions and updated code to .NET v12
1 parent b0b6192 commit 1130984

File tree

2 files changed

+27
-71
lines changed

2 files changed

+27
-71
lines changed

ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,21 @@ public static bool IsImage(IFormFile file)
3030
public static async Task<bool> UploadFileToStorage(Stream fileStream, string fileName, AzureStorageConfig _storageConfig)
3131
{
3232
// Create a URI to the blob
33-
Uri uri = new Uri("https://" + _storageConfig.AccountName + "/.blob.core.windows.net/" + _storageConfig.ImageContainer + "/" + fileName);
33+
Uri blobUri = new Uri("https://" +
34+
_storageConfig.AccountName +
35+
".blob.core.windows.net/" +
36+
_storageConfig.ImageContainer +
37+
"/" + fileName);
3438

35-
// Create storagecredentials object by reading the values from the configuration (appsettings.json)
36-
StorageSharedKeyCredential storageCredentials = new StorageSharedKeyCredential(_storageConfig.AccountName, _storageConfig.AccountKey);
37-
38-
// Create cloudstorage account by passing the storagecredentials
39-
//CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);
40-
//BlobServiceClient blobServiceClient = new BlobServiceClient(uri);
39+
// Create StorageSharedKeyCredentials object by reading
40+
// the values from the configuration (appsettings.json)
41+
StorageSharedKeyCredential storageCredentials =
42+
new StorageSharedKeyCredential(_storageConfig.AccountName, _storageConfig.AccountKey);
4143

4244
// Create the blob client.
43-
BlobClient blobClient = new BlobClient(uri, storageCredentials);
44-
45-
// Get reference to the blob container by passing the name by reading the value from the configuration (appsettings.json)
46-
//CloudBlobContainer container = blobClient.GetContainerReference(_storageConfig.ImageContainer);
47-
//BlobContainerClient container = await blobServiceClient.CreateBlobContainerAsync(_storageConfig.ImageContainer);
48-
49-
// Get the reference to the block blob from the container
50-
//CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
45+
BlobClient blobClient = new BlobClient(blobUri, storageCredentials);
5146

5247
// Upload the file
53-
//await blockBlob.UploadFromStreamAsync(fileStream);
5448
await blobClient.UploadAsync(fileStream);
5549

5650
return await Task.FromResult(true);
@@ -60,49 +54,18 @@ public static async Task<List<string>> GetThumbNailUrls(AzureStorageConfig _stor
6054
{
6155
List<string> thumbnailUrls = new List<string>();
6256

63-
// Create a URI to the thumbnail container
64-
Uri uri = new Uri("https://" + _storageConfig.AccountName + "/.blob.core.windows.net/");
65-
66-
// Create storagecredentials object by reading the values from the configuration (appsettings.json)
67-
//StorageSharedKeyCredential storageCredentials = new StorageSharedKeyCredential(_storageConfig.AccountName, _storageConfig.AccountKey);
68-
69-
// Create cloudstorage account by passing the storagecredentials
70-
//CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);
71-
BlobServiceClient blobServiceClient = new BlobServiceClient(uri);
57+
// Create a URI to the storage account
58+
Uri accountUri = new Uri("https://" + _storageConfig.AccountName + ".blob.core.windows.net/");
7259

73-
// Create blob client
74-
//BlobClient blobClient = new BlobClient(uri, storageCredentials);
60+
// Create BlobServiceClient from the account URI
61+
BlobServiceClient blobServiceClient = new BlobServiceClient(accountUri);
7562

7663
// Get reference to the container
77-
//CloudBlobContainer container = blobClient.GetContainerReference(_storageConfig.ThumbnailContainer);
78-
BlobContainerClient container = await blobServiceClient.CreateBlobContainerAsync(_storageConfig.ThumbnailContainer);
79-
80-
//BlobContinuationToken continuationToken = null;
81-
82-
//BlobResultSegment resultSegment = null;
83-
84-
//Call ListBlobsSegmentedAsync and enumerate the result segment returned, while the continuation token is non-null.
85-
//When the continuation token is null, the last page has been returned and execution can exit the loop.
86-
//do
87-
//{
88-
// //This overload allows control of the page size. You can return all remaining results by passing null for the maxResults parameter,
89-
// //or by calling a different overload.
90-
// resultSegment = await container.ListBlobsSegmentedAsync("", true, BlobListingDetails.All, 10, continuationToken, null, null);
91-
92-
// foreach (var blobItem in resultSegment.Results)
93-
// {
94-
// thumbnailUrls.Add(blobItem.StorageUri.PrimaryUri.ToString());
95-
// }
96-
97-
// //Get the continuation token.
98-
// continuationToken = resultSegment.ContinuationToken;
99-
//}
100-
//while (continuationToken != null);
64+
BlobContainerClient container = blobServiceClient.GetBlobContainerClient(_storageConfig.ThumbnailContainer);
10165

10266
foreach (BlobItem blobItem in container.GetBlobs())
10367
{
104-
string thumbnailUrl = "https://" + _storageConfig.AccountName + "/.blob.core.windows.net/" + _storageConfig.ThumbnailContainer + "/" + blobItem.Name;
105-
thumbnailUrls.Add(thumbnailUrl);
68+
thumbnailUrls.Add(container.Uri + "/" + blobItem.Name);
10669
}
10770

10871
return await Task.FromResult(thumbnailUrls);

ImageResizeWebApp/ImageResizeWebApp/ImageResizeWebApp.csproj

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
</PropertyGroup>
66

77
<PropertyGroup>
8-
<TargetFramework>netcoreapp2.1</TargetFramework>
8+
<TargetFramework>netcoreapp2.0</TargetFramework>
99
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
1010
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
1111
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
1212
<IsPackable>false</IsPackable>
13-
<!-- <PackageTargetFallback>portable-net45+win8</PackageTargetFallback> -->
1413
<ApplicationIcon />
1514
<OutputTypeEx>exe</OutputTypeEx>
1615
<StartupObject></StartupObject>
@@ -19,22 +18,16 @@
1918
<ItemGroup>
2019
<PackageReference Include="Azure.Storage.Blobs" Version="12.2.0" />
2120
<PackageReference Include="Azure.Storage.Common" Version="12.1.1" />
22-
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
23-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.15" />
24-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
25-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
26-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
27-
<PrivateAssets>all</PrivateAssets>
28-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
29-
</PackageReference>
30-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
31-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
32-
<PrivateAssets>all</PrivateAssets>
33-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
34-
</PackageReference>
35-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.1" />
36-
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
37-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
21+
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
22+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
23+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
24+
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
25+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" />
26+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
27+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" />
28+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
29+
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
30+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
3831
</ItemGroup>
3932

4033
<ItemGroup>

0 commit comments

Comments
 (0)