BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
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
<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]; } } |
[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; } } |