Skip to content

Commit

Permalink
Added null check for media in BlobStorage. See #1564
Browse files Browse the repository at this point in the history
  • Loading branch information
tidyui committed Oct 9, 2021
1 parent 3cfa3cb commit a8c6afd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions core/Piranha.Azure.BlobStorage/BlobStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public Task<IStorageSession> OpenAsync()
/// <returns>The public url</returns>
public string GetPublicUrl(Media media, string id)
{
return string.IsNullOrWhiteSpace(id) ? default : $"{_blobContainerClient.Uri.AbsoluteUri}/{GetResourceName(media, id, true)}";
return media == null || string.IsNullOrWhiteSpace(id) ? null :
$"{ _blobContainerClient.Uri.AbsoluteUri }/{ GetResourceName(media, id, true) }";
}

/// <summary>
Expand All @@ -100,7 +101,9 @@ public string GetResourceName(Media media, string filename)
/// <returns>The public url</returns>
public string GetResourceName(Media media, string filename, bool encode)
{
return _naming == BlobStorageNaming.UniqueFileNames ? $"{media.Id}-{(encode ? System.Web.HttpUtility.UrlPathEncode(filename) : filename)}" : $"{media.Id}/{(encode ? System.Web.HttpUtility.UrlPathEncode(filename) : filename)}";
return _naming == BlobStorageNaming.UniqueFileNames ?
$"{ media.Id }-{ (encode ? System.Web.HttpUtility.UrlPathEncode(filename) : filename) }" :
$"{ media.Id }/{ (encode ? System.Web.HttpUtility.UrlPathEncode(filename) : filename) }";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.8.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
<ProjectReference Include="..\Piranha\Piranha.csproj" />
</ItemGroup>
Expand Down

0 comments on commit a8c6afd

Please sign in to comment.