Rich Text Editor Image 401 Unauthorized

I'm trying to setup Rich Text Editor SaverUrl parameter to enable image support. I place the method on a api service that uses app.UseCors, app.UseAuthentication, and app.UseAuthorization. When I try to upload a image, I get the response 401 Unauthorized back. I've tried to use the BeforeUploadImage event, but couldn't find a way to send UseDefaultCredentials with the request or set the client the control is using. Please help on how to accomplish sending the default credentials.


4 Replies

GK Gunasekar Kuppusamy Syncfusion Team October 4, 2021 12:37 PM UTC

Hi George,

Greetings from Syncfusion support.

We have validated your reported query from our end. You can send the additional data using the RichTextEditor BeforeUploadImage event.

Code Snippets:
@using Syncfusion.Blazor.RichTextEditor  
  
    <SfRichTextEditor>  
        <RichTextEditorEventsBeforeUploadImage="BeforeUpload"></RichTextEditorEvents>  
        <RichTextEditorImageSettingsSaveUrl="api/Image/Save"Path="./Files/"/>  
        Syncfusion Rich Text Editor  
    </SfRichTextEditor>  
<br/>  
  
@code{  
  
    publicvoid BeforeUpload(ImageUploadingEventArgs args)  
    {  
        // Adding Headers   
        args.CurrentRequest = new List<object> { new { Authorization = "Syncfusion Test" } };  
  
        // adding custom Form Data   
        args.CustomFormData = new List<object> { new { page = "Testing" } };  
    }  
}  

Refer the below forum to send the additional data to the server.

Regards,
Gunasekar



GF George Franklin October 4, 2021 12:52 PM UTC

I have read that article but it doesn't indicate how to send the authorization. The line of code for the current request, doesn't show how to send UseDefaultCredentials authorization.



GF George Franklin October 4, 2021 08:35 PM UTC

To provide more detail, the preflight request is failing because user credentials are not sent with the request. Since SaveUrl method only accepts a string, there is no way to set UseDefaultCredentials = true for the httpclient it uses.



GK Gunasekar Kuppusamy Syncfusion Team October 5, 2021 04:59 PM UTC

Hi George,

Good day to you.

We have further validated your reported query from our end.

BeforeUploadImage event argument doesnot support to UseDefaultCredentials property, we need to manually append the default credentials in the request.

 As mentioned previously we suggest you set that additional parameters to pass it as key value pair to the server.

Refer the below code snippets,
 
private void onFileSelect(SelectedEventArgs args) 
    { 
 var accessToken = "Basic test123";  
        args.CurrentRequest = new List<object> { new { Authorization = accessToken } };  
 
    } 

[Server side] 
  var auth = Request.Headers["Authorization"]; 

Please let us know if you need further assistance. 

Regards,
Gunasekar


Loader.
Up arrow icon