Skip to content

Commit

Permalink
Add mime type to StorageItem
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Dec 17, 2020
1 parent 36d04cc commit 50ae697
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Sitko.Core.Storage/Sitko.Core.Storage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="MimeMapping" Version="1.0.1.30" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
Expand Down
7 changes: 4 additions & 3 deletions src/Sitko.Core.Storage/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ private StorageItem CreateStorageItem(string destinationPath,
long fileSize,
StorageItemMetadata metadata)
{
var fileName = metadata.FileName ?? Path.GetFileName(destinationPath);
var storageItem = new StorageItem
{
Path = PreparePath(Path.GetDirectoryName(destinationPath))!,
FileName =
metadata.FileName ?? Path.GetFileName(destinationPath),
FileName = fileName,
LastModified = date,
FileSize = fileSize,
FilePath = destinationPath,
MetadataJson = metadata.Data
MetadataJson = metadata.Data,
MimeType = MimeMapping.MimeUtility.GetMimeMapping(fileName)
};
return storageItem;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Sitko.Core.Storage/StorageItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public sealed record StorageItem
/// Size of uploaded file
/// </summary>
public long FileSize { get; set; }

/// <summary>
/// MimeType of uploaded file
/// </summary>
public string MimeType { get; set; } = string.Empty;

/// <summary>
/// Full path to uploaded file in storage
Expand Down
1 change: 1 addition & 0 deletions tests/Sitko.Core.Storage.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public async Task UploadFile()
Assert.NotNull(uploaded);
Assert.NotEqual(0, uploaded.FileSize);
Assert.Equal(fileName, uploaded.FileName);
Assert.Equal("text/plain", uploaded.MimeType);
}

[Fact]
Expand Down

0 comments on commit 50ae697

Please sign in to comment.