How to send authorization header and cookies in saveUrl in RichTextEditor?

My RTE:

<SfRichTextEditor ShowCharCount="true" MaxLength="8000" Placeholder="Enter text(Russian)..." @bind-Value="@_createNewsDto.TextRU">
            <RichTextEditorToolbarSettings Items="@Tools"/>
            <RichTextEditorQuickToolbarSettings Image="@ImageToolbarItem"/>
            @* <RichTextEditorImageSettings AllowedTypes="@_allowedExtensions" SaveUrl="@_saveUrl" Path="./newsMedia/"/> *@
            <RichTextEditorImageSettings AllowedTypes="@_allowedExtensions" SaveUrl="@_saveUrl" Path="./newsMedia/"/>
            <RichTextEditorEvents OnImageUploadSuccess="UploadImageSuccess" ImageDelete="DeleteImageAfterInsert" OnImageRemoving="DeleteImage"></RichTextEditorEvents>
        </SfRichTextEditor>

My HttpClientHandler


public class MyHttpClientHandler : HttpClientHandler
{
    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);


        return await base.SendAsync(request, cancellationToken);
    }
}

Register HttpClient and Handler

builder.Services.AddScoped(sp => new HttpClient(new MyHttpClientHandler()) { BaseAddress = new Uri("https://localhost:7003") });


When I send the request it does not use my Handler although other requests like httpClient.PostAsync etc. use my Handler and it works with authorization but save image doesn't work


1 Reply

VY Vinothkumar Yuvaraj Syncfusion Team September 26, 2024 02:59 PM UTC

Hi Alexandr Cutar,


We have validated your reported query, and you can use the BeforeUploadImage event to send the authorization header with the request. Please see the following code for your reference:


@using Syncfusion.Blazor.RichTextEditor

 

<SfRichTextEditor >

    <RichTextEditorImageSettings SaveUrl="@SaveURL" Path="@Path" />

     <RichTextEditorEvents BeforeUploadImage="onImageUploading" ></RichTextEditorEvents>

</SfRichTextEditor>

 

@code {

    private string SaveURL = "https://blazor.syncfusion.com/services/production/api/RichTextEditor/SaveFile";

    private string Path = "https://blazor.syncfusion.com/services/production/RichTextEditor/";

 

    public void onImageUploading(ImageUploadingEventArgs args)

    {

        // Adding Headers

        args.CurrentRequest = new List<object> { new { Authorization = "Syncfusion Test" } };

    }

}

 


For more details, you can refer to the following API links:


Regards,
Vinothkumar


Loader.
Up arrow icon