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!
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>
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(IListUploadFiles)
{
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
|
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
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
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>
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" }; }
|
Regards,
Vinothkumar
Hi Vinothkumar,
Great!!!
Thanks!!!
Hi Jose,
You're welcome. Please get back to us if you have any further questions.