Hello
I have an issue with the HtmlEditor. I cannot get it to upload images. It keeps sending null to my controller.
Here is my editor code:
<RadzenHtmlEditor @bind-Value=@BindingValue style="min-height: 300px; height: 900px;" UploadUrl="api/media/saveimage">
<RadzenHtmlEditorUndo />
<RadzenHtmlEditorRedo />
<RadzenHtmlEditorSeparator />
<RadzenHtmlEditorBold />
<RadzenHtmlEditorItalic />
<RadzenHtmlEditorUnderline />
<RadzenHtmlEditorStrikeThrough />
<RadzenHtmlEditorSeparator />
<RadzenHtmlEditorAlignLeft />
<RadzenHtmlEditorAlignCenter />
<RadzenHtmlEditorAlignRight />
<RadzenHtmlEditorJustify />
<RadzenHtmlEditorSeparator />
<RadzenHtmlEditorIndent />
<RadzenHtmlEditorOutdent />
<RadzenHtmlEditorUnorderedList />
<RadzenHtmlEditorOrderedList />
<RadzenHtmlEditorSeparator />
<RadzenHtmlEditorColor />
<RadzenHtmlEditorBackground />
<RadzenHtmlEditorRemoveFormat />
<RadzenHtmlEditorSeparator />
<RadzenHtmlEditorSubscript />
<RadzenHtmlEditorSuperscript />
<RadzenHtmlEditorSeparator />
<RadzenHtmlEditorLink />
<RadzenHtmlEditorUnlink />
<RadzenHtmlEditorImage />
<RadzenHtmlEditorFontName />
<RadzenHtmlEditorFontSize />
<RadzenHtmlEditorFormatBlock />
</RadzenHtmlEditor>
And here is the controller method:
[Route("api/media/saveimage")]
[HttpPost]
[Authorize(Policy = Policies.AdminMvcUser)]
public async Task<IActionResult> SaveMedia(IFormFile? uploadFiles)
{
try
{
if (uploadFiles is null)
{
return BadRequest("Ingen fil fundet");
}
var memoryStream = new MemoryStream();
await uploadFiles.CopyToAsync(memoryStream);
var filesCount = Request.Form.Files.Count;
if (Request.ContentType is not null && !Request.ContentType.StartsWith(MultipartContentType))
return BadRequest("Contenttype er ikke korrekt");
if (filesCount == 0)
return BadRequest("Ingen fil fundet");
// Get HTTP posted file based on the fieldname.
// Check if the file is valid.
if (!Check(uploadFiles.FileName, uploadFiles.ContentType))
return BadRequest("Fil ikke gyldig");
var medie = new Medie
{
Name = uploadFiles.FileName.Trim('\"'),
ParentId = _imageService.TempFolderGuid,
ContentLength = uploadFiles.Length,
Content = memoryStream.ToArray()
};
try
{
var imageId = await _imageService.Medier_InsertMedie(medie);
Response.Headers.Add("itemLocation", imageId.Id.ToString());
var url = $"api/images/{imageId.Id.ToString()}.jpg";
return Ok(new {Url = url});
}
catch
{
return BadRequest("Kunne ikke gemme billede");
}
}
catch
{
return StatusCode(500);
}
}
It hits the controller. But the IFormFile input is null, so it always enter the first if check