HttpPostedFileBase is null

10 posts, 0 answers
  1. Steven
    Steven avatar
    29 posts
    Member since:
    Jul 2012

    Posted 11 Oct 2012 Link to this post

    *** SOLUTION FOUND (see EDIT below) ***

    I have followed some of the examples for declaring my MVC controller method for use with the Upload component.  My upload handler declaration is as follows:

    public ActionResult Upload(IEnumerable<HttpPostedFileBase> attachments, long inventoryID, long imageType)
    {
    }

    I have set my Upload control to use Async.  However, whenever I try to upload a file, the attachments parameters is always passed null.

    I have also tried:
    • Renaming attachments to files
    • Declaring IEnumerable<HttpPostedFileBase> as IEnumerable<HttpPostedFile>
    • Declaring the attachments parameter as both HttpPostedFileBase and HttpPostedFile (singular

    I have written some JavaScript (as the Upload event) to pass the additional parameters (inventoryID and imageType) which are always passed successfully.

        function imageUploadUpload(e) {
            e.data = { inventoryID : @Model.InventoryID, imageType: imageType };
        }

    I have tried removing the Upload event/handler to see if this makes a difference, but still have the same problem.

    Any idea what is going on?

    Thank you.

    *** EDIT ***

    I found the solution here.  The name of the Upload component must match the name of the parameter that holds the HttpPostedFileBase.  I had named my Upload component imageUpload.  When I renamed the parameter to imageUpload, it worked fine!


  2. Bill
    Bill avatar
    82 posts
    Member since:
    Feb 2013

    Posted 12 Jun 2013 Link to this post

    I ran into this exact same issue.

    I can confirm that after naming the parameter in the controller the exact same name as what I named the KendoUI upload control, it worked.  Thanks Steven.
  3. Soori
    Soori avatar
    7 posts
    Member since:
    Jun 2013

    Posted 06 Aug 2013 Link to this post

    Thanks. That solved my issue .
  4. Soori
    Soori avatar
    7 posts
    Member since:
    Jun 2013

    Posted 17 Mar 2014 in reply to Bill Link to this post

    Name attribute of the  KendoUI upload control should be same as the parameter name of Controller. In following example it is 'fille'

    <input name="file" id="fileUploader" type="file" />


     public ActionResult UploadFile(HttpPostedFileBase file, String subject, String doc, String ref)
    {
    }
  5. elke
    elke avatar
    4 posts
    Member since:
    Jan 2017

    Posted 10 Feb 2017 in reply to Soori Link to this post

    that is a problem if you want to use the uploader in a patial view that is used in multiple tabs or pills on the same page.

    ex. i have a product "dress" and the dress had multiple "finishes", ex red, blue and yellow.

    i made tabs per finish and now i want to upload picuters on differet tabs.

    my uploader requires a unique identifier per tab, so it's called "uploader_blue", "uploader_red",... 

    however, the controler and the action is always the same. i cant make 5 actions with the same name and different parameters.......

     

  6. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 10 Feb 2017 Link to this post

    Hello elke,

    In such cases you should use the async.saveField configuration option and specify it to match the name of the controller action parameter. This will allow you to keep the different names of the uploads.

    Regards,
    Dimiter Madjarov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  7. Attila
    Attila avatar
    22 posts
    Member since:
    Oct 2016

    Posted 28 Sep 2017 in reply to Steven Link to this post

    Goddamnit!!! After debugging for hours this saved my evening! Thanks a lot buddy, it worked for me too!
  8. Piyush Bhatt
    Piyush Bhatt avatar
    20 posts
    Member since:
    Oct 2014

    Posted 07 Jul 2018 Link to this post

    I had a silly typo in action signature - as - DocumentUpload(IEnumerable<HttpPostedFile> files)

    and the files collection was always empty. It took me 4 hours to figure out the type should have been FileBase as in below..

    DocumentUpload(IEnumerable<HttpPostedFileBase> files)

  9. Chris
    Chris avatar
    116 posts
    Member since:
    Oct 2015

    Posted 29 Apr 2019 in reply to Steven Link to this post

    Thanks, I found the reason of the problem FINALLY(files always null).

    --

    "The name of the Upload component must match the name of the parameter 
     that holds the HttpPostedFileBase..."

    I don't why the telerik official Upload documentation/sample 
    NEVER notice the developer this point explicitly(not just "files") ???
     
    Upload / Asynchronous Upload
    https://demos.telerik.com/aspnet-mvc/upload/async

            public ActionResult Async_Save(IEnumerable<HttpPostedFileBase> files)
            {
                // The Name of the Upload component is "files"

    -> "files" parameter name must same as the name(element attribute - "name") of the Upload component. 
      
       <input type="file" name="files" /> IEnumerable<HttpPostedFileBase> files
       <input type="file" name="file1" /> IEnumerable<HttpPostedFileBase> file1
       <input type="file" name="file2" /> IEnumerable<HttpPostedFileBase> file2

    async.saveUrl
    https://docs.telerik.com/kendo-ui/api/javascript/ui/upload/configuration/async.saveurl

    -> have no any description about this.

    so sad...

    Best regards

    Chris







  10. Petar
    Admin
    Petar avatar
    333 posts

    Posted 02 May 2019 Link to this post

    Hello Chris.

    I am sorry for the inconvenience you have experienced and thank you for your constructive feedback!

    We will consider adding more details and explicitly pointing out that the name of the parameter that holds HttpPostedFileBase should be the same as the name of the Upload component.

    Regards,
    Petar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top