Skip to content

Added Ability to Check File Exists #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.22.2" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.24.1" />
<PackageReference Include="ICG.NetCore.Utilities" Version="6.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.6" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
27 changes: 27 additions & 0 deletions src/AspNetCore.Utilities.CloudStorage/AzureCloudStorageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;
using Azure.Storage.Blobs;
Expand Down Expand Up @@ -94,6 +95,17 @@
/// <returns></returns>
Task<List<BlobInfo>> ListBlobs(string container);

/// <summary>
/// Allows checking to see if a blog exists in the provided container based on the full object URL
/// </summary>
/// <remarks>
/// Behind the scenes this utilizes the ExistsAsync method of the BlobClient, which will return true if the blob exists or false if it does not.
/// </remarks>
/// <param name="expectedContainer">The container that this was expected in</param>
/// <param name="fullObjectUrl"></param>
/// <returns></returns>
Task<bool> BlobExists(string expectedContainer, string fullObjectUrl);

/// <summary>
/// Creates a SAS token to access an object with the default duration
/// </summary>
Expand Down Expand Up @@ -342,6 +354,21 @@
return blobList;
}

[ExcludeFromCodeCoverage(Justification = "Would require integration test to fully validate given direct calls to Azure Blob Storage")]
/// <inheritdoc />

Check warning on line 358 in src/AspNetCore.Utilities.CloudStorage/AzureCloudStorageProvider.cs

View workflow job for this annotation

GitHub Actions / Validate Build

XML comment is not placed on a valid language element

Check warning on line 358 in src/AspNetCore.Utilities.CloudStorage/AzureCloudStorageProvider.cs

View workflow job for this annotation

GitHub Actions / Validate Build

XML comment is not placed on a valid language element
public async Task<bool> BlobExists(string expectedContainer, string fullObjectUrl)

Check warning on line 359 in src/AspNetCore.Utilities.CloudStorage/AzureCloudStorageProvider.cs

View workflow job for this annotation

GitHub Actions / Validate Build

Missing XML comment for publicly visible type or member 'AzureCloudStorageProvider.BlobExists(string, string)'

Check warning on line 359 in src/AspNetCore.Utilities.CloudStorage/AzureCloudStorageProvider.cs

View workflow job for this annotation

GitHub Actions / Validate Build

Missing XML comment for publicly visible type or member 'AzureCloudStorageProvider.BlobExists(string, string)'
{
var objectName = GetObjectName(expectedContainer, fullObjectUrl);
if (objectName == null)
{
return false;
}
var blobClient = new BlobServiceClient(_storageOptions.Value.StorageConnectionString);
var containerClient = blobClient.GetBlobContainerClient(expectedContainer.ToLower());
var itemClient = containerClient.GetBlobClient(objectName);
return await itemClient.ExistsAsync();
}

/// <inheritdoc />
public string CreateSASUrl(string fullObjectPath)
{
Expand Down