File failed to upload Error

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("");

        }

        

    }


1 Reply

BC Berly Christopher Syncfusion Team August 12, 2021 01:13 PM UTC

Hi Randy, 
  
Greetings from Syncfusion support. 
  
We have checked the File Uploader component in the ASP.NET Core 5.0 application and file is get uploaded successfully. For your convenience, we have prepared the sample and attached it below. 
  
 
  
  
To know more about this, please refer the below documentation link. 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon