refactor(EConnectClient): GetMimeType hinzufügen, um den MIME-Typ basierend auf dem Dateinamen zuzuweisen
This commit is contained in:
parent
9256dc6baf
commit
beadc3c4bb
@ -1,5 +1,6 @@
|
|||||||
using Leanetec.EConnect.Client.Interface;
|
using Leanetec.EConnect.Client.Interface;
|
||||||
using Leanetec.EConnect.Domain.Entities;
|
using Leanetec.EConnect.Domain.Entities;
|
||||||
|
using Microsoft.AspNetCore.StaticFiles;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
@ -136,7 +137,8 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
|||||||
|
|
||||||
// add file type
|
// add file type
|
||||||
var fileContent = new StreamContent(stream);
|
var fileContent = new StreamContent(stream);
|
||||||
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
|
var mimeType = GetMimeType(fileName);
|
||||||
|
fileContent.Headers.ContentType = new MediaTypeHeaderValue(mimeType);
|
||||||
|
|
||||||
// Create multipart form data form
|
// Create multipart form data form
|
||||||
using var form = new MultipartFormDataContent
|
using var form = new MultipartFormDataContent
|
||||||
@ -166,4 +168,14 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
|||||||
: null
|
: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetMimeType(string fileName)
|
||||||
|
{
|
||||||
|
var provider = new FileExtensionContentTypeProvider();
|
||||||
|
if (!provider.TryGetContentType(fileName, out var contentType))
|
||||||
|
{
|
||||||
|
contentType = "application/octet-stream"; // fallback
|
||||||
|
}
|
||||||
|
return contentType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.3.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.19" />
|
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.19" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user