Bug copy paste images inside RTE

Hi

I just update my wasm project to last version 20.2.0.38

Before this update copy and paste images inside RTE without using image icon in toolbar was fine!

With this new version this not works.

Please check my video

I need to rename the files in the api, just like your sample code, this code is working.

I get null reference exception in this function y my wasm code when copy paste images without use toolbar button

        private async Task ImageUploadSuccess(ImageSuccessEventArgs args)
        {
            try
            {
                var headers1 = args.Response.Headers.ToString();
                header = headers1.Split("name: ");
                header = header[0]?.Split("\r");
                var s = URL_STORE_IMAGES.TrimEnd('/') + @"/" + header[1].TrimStart().TrimEnd().Replace("\r\n", string.Empty).Replace("\n", string.Empty).Replace("content-type:", string.Empty).Replace(" ", string.Empty);
                args.File.Name = s; // <-- line with exception
            }
            catch (Exception ex)
            {
            }
        }

Please help!



Attachment: bandicam_20220720_130928214_2a3cf443.rar

11 Replies

VJ Vinitha Jeyakumar Syncfusion Team July 21, 2022 12:42 PM UTC

Hi Jose,


We have tried to replicate the reported issue by checking the video you have attached and used the code you have shared. but we didn't face any issues while copy and paste the images into the RTE in latest version. We have also prepared a sample and video illustration for your reference.



Can you please share us with the entire code snippet or runnable issue reproducing sample to further validate on our end.

Regards,
Vinitha


JL jose luis barajas July 21, 2022 02:03 PM UTC

Hi  Vinitha 

I am sending the images to my API, where I rename the file and the URL is placed in the editor,

The error is when the image is pasted without using the image icon that is in the toolbar.

Check my code 

                        <SfRichTextEditor

                            @ref="rteInstance1" @bind-Value="@TIMER_NOTES.NOTE">

                            <RichTextEditorToolbarSettings Items="@Utils.ToolbarRTE" />

                            <RichTextEditorImageSettings SaveUrl="@END_POINT" Path=""

                                                     ResizeByPercent="false" Width="500"/>

                            <RichTextEditorEvents OnImageUploadSuccess="@ImageUploadSuccess"> </RichTextEditorEvents>

                        </SfRichTextEditor>



VJ Vinitha Jeyakumar Syncfusion Team July 22, 2022 12:11 PM UTC

Hi Jose,


We have also tried to replicate the issue at our end by using the SaveUrl API and renamed the image using OnImageUploadSuccess event. but unfortunately we didn't face any issues while copy and pasting the images into the RTE without using image toolbar.

Can you please share the below details,

  • Your old package version(from where you upgraded to the latest V20.2.38)?
  • Have you facing any script errors?
  • If possible, can you please share us with the issue replicating simple runnable sample?
  • Else please share the entire code snippet to run a sample at our end.

Regards,
Vinitha


JL jose luis barajas July 22, 2022 07:09 PM UTC

Hi Vinitha

Check my new video with previous version 20.1.061. The file is renamed well in the api.
Both versions use the same API,
With version 20.2.0.38 not works
after paste image I get this exception in console's browser

rte_image_1.png:1 GET http://localhost:44100/rte_image_1.png 404 (Not Found)

this is because I get one exception in ImageUploadSuccess function
This exception only occurs​ when paste image without toolbar button, weird!!!

Wasm code

private async Task ImageUploadSuccess(ImageSuccessEventArgs args)
{
try
{
var headers = args.Response.Headers.ToString();
header = headers.Split(":");
if (header.Length == 3)
{
var s = URL_STORE_IMAGES.TrimEnd('/') + @"/" + header[2].TrimStart().TrimEnd().Replace("\r", string.Empty).Replace("", string.Empty).Replace("content-type:", string.Empty).Replace(" ", string.Empty);
args.File.Name = s;
}
}
catch (Exception ex)
{
}
}

Razor code
@ref="rteInstance1" @bind-Value="@TIMER_NOTES.NOTES">
ResizeByPercent="false" Width="500"/>


Api method

[HttpPost("[action]")]
[Route("SaveImages")]
[AllowAnonymous]
public void SaveContenedorRteImages(IList UploadFiles)
{
try
{
foreach (IFormFile file in UploadFiles)
{
if (UploadFiles.Count != 0)
{
string filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName?.Trim('"');
if (!Directory.Exists(_webHostEnvironment.ContentRootPath + "\\path1\\path2\\"))
Directory.CreateDirectory(_webHostEnvironment.ContentRootPath + "\\path1\\path2\\");
imageFileName = "rte_img_" + Guid.NewGuid().ToString() + "_" + filename;
string path = _webHostEnvironment.ContentRootPath + "\\path1\\path2\\" + imageFileName;
if (!System.IO.File.Exists(path))
{
using (FileStream fs = System.IO.File.Create(path))
{
file.CopyTo(fs);
fs.Flush();
fs.Close();
}
Response.Headers.Add("name", imageFileName);
Response.ContentType = imageFileName;
Response.StatusCode = 200;
}
}
}
}
catch (Exception e)
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.HttpContext.Features.Get().ReasonPhrase = e.Message;
}
}


Head in index.html
Im using material.css

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>Web</title>
    <base rel='nofollow' href="/" />

    <link rel='nofollow' href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link rel='nofollow' href="css/app.css" rel="stylesheet" />
    <link rel='nofollow' href="Web.Client.styles.css" rel="stylesheet" />

    <link rel="stylesheet" rel='nofollow' href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link rel="stylesheet" rel='nofollow' href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">

    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-textbox.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-datepicker.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-timepicker.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-dropdownlist.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-listbox.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-contextmenu.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-grid.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-tab.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-toolbar.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-schedule.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-tab.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-treegrid.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-spinner.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-dialog.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-richtexteditor.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-kanban.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-dialog.min.js" type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/blazor/20.2.38/sf-accordion.min.js" type="text/javascript"></script>


    <link rel='nofollow' href="https://cdn.syncfusion.com/blazor/20.2.38/styles/material.css" rel="stylesheet" />


    <link rel='nofollow' href="css/Icons.css" rel="stylesheet" />
    <link rel='nofollow' href="css/loader.css" rel="stylesheet" />
    <link rel='nofollow' href="css/dragdrop.css" rel="stylesheet" />
    <link rel='nofollow' href="css/global.css" rel="stylesheet" />


    <script src="_content/BlazorAnimate/blazorAnimateInterop.js"></script>


    <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js" integrity="sha512-90vH1Z83AJY9DmlWa8WkjkV79yfS2n2Oxhsi2dZbIv0nC4E6m5AbH8Nh156kkM7JePmqD6tcZsfad1ueoaovww==" crossorigin="anonymous"></script>


    <link rel='nofollow' href="Web.Client.styles.css" rel="stylesheet" />
</head>

Attachment: video_with_version_20_1_0_61_63a073b3.rar


VJ Vinitha Jeyakumar Syncfusion Team July 25, 2022 01:44 PM UTC

Hi Jose,


In your sample code, you have defined the path property in RichTextEditorImageSettings as empty string and that is the cause of the issue you have faced. So please provide a location to store the image in the Path property to resolve the reported issue at your end.

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




Regards,
Vinitha


JL jose luis barajas July 26, 2022 12:31 AM UTC

Hi Vinita, thanks for your response

I just added this value in Path attribute, not works.

Also consider that the images are not saved where client is installed (web app), so I need to save and rename then in another server.


Another issue is

header response, I not get new name in header response from my controller method.

...

I have:

Response.Headers.Add("name", imageFileName); // NAME variable NOT REACH IN CLIENT CODE. ImageuploadSucess

Response.StatusCode = 200;

Response.ContentType = "application/json; charset=utf-8";


Also can you check in your end this function, using paste directly in RTE and using toolbar icon?

private async Task ImageUploadSuccess(ImageSuccessEventArgs args)

{

try

{

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

header = headers.Split(":");

args.File.Name = "anyname.png"

}

catch (Exception ex)

{


}

}


Seems the same commented in this post

https://www.syncfusion.com/forums/153257/set-header-for-image-upload-in-rich-text-editor


Please help!


Attachment: problem_58323026.rar



VJ Vinitha Jeyakumar Syncfusion Team July 27, 2022 10:47 AM UTC

Hi Jose,

We have created a new ticket under your account to follow up with this query. We suggest you to follow up with the ticket for further updates. Please login using the below link.

https://support.syncfusion.com/support


Regards,

Vinitha



JL jose luis barajas July 31, 2023 07:39 PM UTC

Hi

I need your help again with this ticket.

I need to disable copy paste images directly inside the text editor area, I only enable this option to the user using the upload image icon in the toolbar.

Can you help me please!


                                            <SfRichTextEditor @bind-Value="@TESTSAVEIMAGES">

                                                <RichTextEditorImageSettings SaveUrl="@END_POINT_SAVE_IMAGES_FROM_RTE2" Path="its not important if path has data or not"

                                                                             ResizeByPercent="true" MaxWidth="900" MaxHeight="900" />

                                                <RichTextEditorEvents OnImageUploadSuccess="@ImageUploadSuccess"> </RichTextEditorEvents>

                                            </SfRichTextEditor>




VY Vinothkumar Yuvaraj Syncfusion Team August 1, 2023 12:10 PM UTC

Hi Jose,


To disable the image, paste into the Rich Text Editor, you can use the PasteCleanupSettings DeniedTags property. This will remove the particular element when pasted into the Rich Text Editor. Please see the following code and attached sample for your reference.


  <SfRichTextEditor ShowCharCount="true" EnableResize="true"  MaxLength="2000">

<RichTextEditorPasteCleanupSettings DeniedTags="@Deniedtags" />

  </SfRichTextEditor>

@code{

   private string[] Deniedtags { get; set; } = { "img" };

}

 


API Link : https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.RichTextEditor.RichTextEditorPasteCleanupSettings.html#properties


Regards,

Vinothkumar


Attachment: RTE_Wasm_new_ef0f82eb_c724a61f.zip


JL jose luis barajas August 2, 2023 01:54 AM UTC

Hi Vinothkumar,

Great!!!

Thanks!!!



VY Vinothkumar Yuvaraj Syncfusion Team August 4, 2023 05:46 AM UTC

Hi Jose,


You're welcome. Please get back to us if you have any further questions.


Loader.
Up arrow icon