Cannot get uploaded files in Controller level

Hello,

I use File Upload in NET Core to upload PDF files into server.

For some reason the model binder not catch the uploaded files, the object is always null.


This is my view code:

 <div class="col col-lg-12 text-center">
     @{
         var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings
         {
             SaveUrl = Url.Action("SaveXls", "UploadZ"),
             RemoveUrl = "https://ej2.syncfusion.com/services/api/uploadbox/Remove"
         };
     }

     <div class="text-center" style="background-color: lightgoldenrodyellow !important">
         <ejs-uploader id="uploadFiles"
                         asyncSettings="@asyncSettings"
                         success="onUploadSuccess"
                         failure="onUploadFailure"
                         autoUpload="true"
                         allowedExtensions=".pdf"></ejs-uploader>
         <script>
             function onFileUpload(args) {
                 debugger
                 args.customFormData = [{ 'name': 'Syncfusion INC' }];
             }
             function onUploadSuccess(args) {
                 if (args.operation === 'upload') {
                     console.log('success');
                 }
             }
             function onUploadFailure(args) {
                 console.log('failed');
             }
         </script>
     </div>
 </div>

This is my Controller code:

 public class UploadZController : ControllerBase
 {
     public UploadZController()
     {
     }

     [HttpPost("SaveXls")]
     public async Task<IActionResult> SaveXls(IList<IFormFile> fileData)
     {
         var _uploadFolder = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", "xls");


         return Ok();
     }
 }

fileData is always null, I try lot of variations for method, for example:

public async Task<IActionResult> SaveXls(FormFileCollection fileData)

public async Task<IActionResult> SaveXls([FromForm] FormFileCollection fileData)

public async Task<IActionResult> SaveXls(IList<IFormFile> fileData)

public async Task<IActionResult> SaveXls([FromForm] IList<IFormFile> fileData)

Result is always null.

But when I check the File in the Request object, it is here:

Image_5860_1737535431207

Can you help me please why model binder not working?

Thank you!


1 Reply

YS Yohapuja Selvakumaran Syncfusion Team January 27, 2025 01:58 PM UTC

Hi SZL,

Thank you for reaching out to us.

To assist you with your requirement of accessing the uploaded file in the controller and passing custom data, we have created a detailed Knowledge Base (KB) article. You can refer to it for step-by-step instructions and examples on how to handle custom parameters when working with the File Upload control.

KB ArticleHandling Custom Parameters in JavaScript File Upload control

This article provides insights on to retrieve the uploaded file from the request and process it within your server-side controller and Understand how to send additional custom parameters along with the uploaded file, making it possible to include metadata or other necessary data in the upload request.

If you are still facing any issues or have any questions regarding the implementation, please do not hesitate to reach out to us. We are more than happy to assist you further.

We look forward to your feedback and hope the KB article helps resolve your query.



Regards,

Yohapuja S


Loader.
Up arrow icon