Hello,
I am using ASP.net CORE 5 I can't get the upload control to work. I keep getting the message File failed to upload.
I am able to hit the endpoint /Upload/Save with a post operation using Postman.
Here is my Control:
@{
var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "/Upload/Save", ChunkSize = 500000 };
}
<ejs-uploader id="uploadFiles" asyncSettings="@asyncSettings" autoUpload="false"></ejs-uploader>
And is my controller code:
[ApiController]
[Route("[controller]")]
public class UploadController : ControllerBase
{
//
// GET: /UploadDefault/
private IWebHostEnvironment hostingEnv;
public UploadController(IWebHostEnvironment env)
{
this.hostingEnv = env;
}
[HttpPost]
public IActionResult Save(IList<IFormFile> chunkFile, IList<IFormFile> UploadFiles)
{
try
{
foreach (var file in UploadFiles)
{
if (UploadFiles != null)
{
var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
filename = hostingEnv.WebRootPath + $@"\{filename}";
if (!System.IO.File.Exists(filename))
{
//using (FileStream fs = System.IO.File.Create(filename))
//{
// file.CopyTo(fs);
// fs.Flush();
//}
}
else
{
Response.Clear();
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File already exists.";
}
}
}
}
catch (Exception e)
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "No Content";
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message;
}
return Content("");
}
}