|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: HttpClientInstance in Blazor RichTextEditor Component | Syncfusion |
| 4 | +description: Checkout and learn here all about HttpClientInstance in Syncfusion Blazor RichTextEditor component and much more. |
| 5 | +platform: Blazor |
| 6 | +control: RichTextEditor |
| 7 | +documentation: ug |
| 8 | +--- |
| 9 | + |
| 10 | +# HttpClientInstance in Blazor RichTextEditor Component |
| 11 | + |
| 12 | +The Rich Text Editor component in Blazor enables you to utilize the `HttpClientInstance` property to append the custom HttpClient instance to all file upload and download requests. This approach offers flexibility in managing authentication and custom request configurations for Word Import, Word and PDF Export and image/audio/video insertions. |
| 13 | + |
| 14 | +The following example illustrates how to configure the Rich Text Editor component with HttpClient in a Blazor application. |
| 15 | + |
| 16 | +```razor |
| 17 | +@using Syncfusion.Blazor.RichTextEditor |
| 18 | +@inject HttpClient httpClient |
| 19 | +
|
| 20 | +<SfRichTextEditor HttpClientInstance="@httpClient"> |
| 21 | + <RichTextEditorImageSettings SaveUrl="https://your_api.com/upload/image"> |
| 22 | + </RichTextEditorImageSettings> |
| 23 | + <RichTextEditorAudioSettings SaveUrl="https://your_api.com/upload/audio"> |
| 24 | + </RichTextEditorAudioSettings> |
| 25 | + <RichTextEditorVideoSettings SaveUrl="https://your_api.com/upload/video"> |
| 26 | + </RichTextEditorVideoSettings> |
| 27 | +</SfRichTextEditor> |
| 28 | +
|
| 29 | +@code { |
| 30 | + protected override async Task OnInitializedAsync() |
| 31 | + { |
| 32 | + // Adding authorization header to HTTP client |
| 33 | + httpClient.DefaultRequestHeaders.Add("Authorization_1", "syncfusion"); |
| 34 | + await base.OnInitializedAsync(); |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +## Program.cs |
| 40 | + |
| 41 | +```csharp |
| 42 | +using Syncfusion.Blazor; |
| 43 | + |
| 44 | +var builder = WebApplication.CreateBuilder(args); |
| 45 | + |
| 46 | +// Add services to the container. |
| 47 | +builder.Services.AddRazorComponents() |
| 48 | + .AddInteractiveServerComponents(); |
| 49 | +builder.Services.AddSyncfusionBlazor(); |
| 50 | +builder.Services.AddScoped(sp => |
| 51 | +{ |
| 52 | + var httpClient = new HttpClient |
| 53 | + { |
| 54 | + BaseAddress = new Uri("https://your_api.com/") |
| 55 | + }; |
| 56 | + |
| 57 | + // Add custom header |
| 58 | + httpClient.DefaultRequestHeaders.Add("Custom-Header", "YourCustomValue"); |
| 59 | + return httpClient; |
| 60 | +}); |
| 61 | +var app = builder.Build(); |
| 62 | + |
| 63 | +``` |
0 commit comments