-
Notifications
You must be signed in to change notification settings - Fork 112
Open
Labels
awaiting responseWaiting for the author of the issue to provide more information or answer a questionWaiting for the author of the issue to provide more information or answer a questiongood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededintegrationA new .NET Aspire integrationA new .NET Aspire integration
Description
.NET Aspire issue link
Overview
Integrating with apache's Tika in dotnet isn't trivial and requires running https://github.com/apache/tika-docker
something like this:
public class TikaContainer(string name) : ContainerResource(name)
{
}
public static class TikaContainerBuilderExtensions
{
public static IResourceBuilder<TikaContainer> AddApacheTika(this IDistributedApplicationBuilder builder, string name)
{
var container = new TikaContainer(name);
return builder.AddResource(container)
.WithImage("apache/tika", tag: "3.0.0.0")
.WithImageRegistry("docker.io")
.WithHttpEndpoint(port: 9998, targetPort: 9998)
.WithHttpHealthCheck("/version");
}
}
Usage example
// app-host
var tika = builder.AddApacheTika("apache-tika");
// service config
builder.Services.AddHttpClient<TikaClient>(options => options.BaseAddress = new Uri("http://apache-tika"));
// the-client
public class TikaClient(HttpClient httpClient)
{
public async Task<string> GetFileContent(byte[] fileContent)
{
var request = new HttpRequestMessage(HttpMethod.Put, "/tika")
{
Content = new ByteArrayContent(fileContent),
Headers =
{
Accept =
{
new MediaTypeWithQualityHeaderValue("text/plain")
}
}
};
var response = await _httpClient.SendAsync(request);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync();
}
else
{
throw new Exception($"Failed to get file content. Status code: {response.StatusCode}");
}
}
}
Additional context
No response
Help us help you
Yes, I'd like to be assigned to work on this item
Metadata
Metadata
Assignees
Labels
awaiting responseWaiting for the author of the issue to provide more information or answer a questionWaiting for the author of the issue to provide more information or answer a questiongood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededintegrationA new .NET Aspire integrationA new .NET Aspire integration