We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

UI down or problem with OnImageUploadSuccess Event

I'm trying to upload image to Azure storage. my code is below.


SaveUrl="@baseUri"

Path="https://azure.blob.core.windows.net/containerName/rtfeditor_images/" />


OnImageUploadSuccess code is below.

public string[] header { get; set; }

private void ImageUploadSuccess(ImageSuccessEventArgs args) {

var headers = args.Response.Headers.ToString();

header = headers.Split("name: ");

header = header[1].Split("\r");

// Update the modified image name to display a image in the editor.

args.File.Name = header[0];

}



*. It has no problem with Image add dialog, but UI down or problem when i trying paste image to richeditcontrol

1. args.File.Name = header[0]; ==> null error

2. in the control, img source link not change as SaveUrl address


1 Reply

VJ Vinitha Jeyakumar Syncfusion Team February 28, 2023 10:08 AM UTC

Hi Charles,

We have tried to replicate the reported issue at our end by renaming the file name using the OnImageUploadSuccess event of the RichTextEditor control. but we didn't face any issues as you reported. we have also prepared a sample for your reference.

Code snippet:
<SfRichTextEditor>
    <RichTextEditorImageSettings SaveUrl="api/Image/Save" Path="./Images/"></RichTextEditorImageSettings>
    <RichTextEditorEvents OnImageUploadSuccess="@ImageUploadSuccess" />
</SfRichTextEditor>

@code {
    public string[] header { get; set; }

    private void ImageUploadSuccess(ImageSuccessEventArgs args)
    {
        var headers = args.Response.Headers.ToString();
        header = headers.Split("name: ");
        header = header[1].Split("\r");
        // Update the modified image name to display a image in the editor.
        args.File.Name = header[0];
    }
}
ImageController.cs
[HttpPost("[action]")]
        [Route("api/Image/Save")]
        public void Save(IList<IFormFile> UploadFiles)
        {
            try
            {
                foreach (IFormFile file in UploadFiles)
                {
                    if (UploadFiles != null)
                    {
                        string targetPath = hostingEnv.ContentRootPath + "\\wwwroot\\Images";
                        string filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');

                        // Create a new directory, if it does not exists
                        if (!Directory.Exists(targetPath))
                        {
                            Directory.CreateDirectory(targetPath);
                        }

                        imageFileName = filename;
                        string path = hostingEnv.WebRootPath + "\\Images" + $@"\{filename}";

                        // Rename a uploaded image file name
                        while (System.IO.File.Exists(path))
                        {
                            imageFileName = "rteImage" + x + "-" + filename;
                            path = hostingEnv.WebRootPath + "\\Images" + $@"\rteImage{x}-{filename}";
                            x++;
                        }

                        if (!System.IO.File.Exists(path))
                        {
                            using (FileStream fs = System.IO.File.Create(path))
                            {
                                file.CopyTo(fs);
                                fs.Flush();
                                fs.Close();
                            }

                            // Modified file name shared through response header by adding custom header
                            Response.Headers.Add("name", imageFileName);
                            Response.StatusCode = 200;
                            Response.ContentType = "application/json; charset=utf-8";
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Response.Clear();
                Response.ContentType = "application/json; charset=utf-8";
                Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message;
            }
        }


If still issue persists at your end. can you please share us with the issue replicating runnable sample or modify the attached sample with the issue reproducing code for further validation

Regards,
Vinitha

Attachment: SfRichTextEditor_image_save_c7de553d.zip

Loader.
Live Chat Icon For mobile
Up arrow icon