This is a migrated thread and some comments may be shown as answers.

HttpPostedFileBase is null

9 Answers 745 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 12 Oct 2012, 12:40 AM
*** 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!


9 Answers, 1 is accepted

Sort by
0
Bill
Top achievements
Rank 1
answered on 12 Jun 2013, 04:08 PM
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.
0
Soori
Top achievements
Rank 1
answered on 06 Aug 2013, 12:49 PM
Thanks. That solved my issue .
0
Soori
Top achievements
Rank 1
answered on 17 Mar 2014, 09:11 AM
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)
{
}
0
elke
Top achievements
Rank 1
answered on 10 Feb 2017, 01:21 PM

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.......

 

0
Dimiter Madjarov
Telerik team
answered on 10 Feb 2017, 01:55 PM

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!
 
0
Attila
Top achievements
Rank 2
answered on 28 Sep 2017, 05:46 PM
Goddamnit!!! After debugging for hours this saved my evening! Thanks a lot buddy, it worked for me too!
0
Piyush Bhatt
Top achievements
Rank 1
answered on 07 Jul 2018, 11:40 PM

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)

0
Chris
Top achievements
Rank 1
Veteran
Iron
answered on 30 Apr 2019, 03:30 AM
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







0
Petar
Telerik team
answered on 02 May 2019, 02:26 PM
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.
Tags
Upload
Asked by
Steven
Top achievements
Rank 1
Answers by
Bill
Top achievements
Rank 1
Soori
Top achievements
Rank 1
elke
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Attila
Top achievements
Rank 2
Piyush Bhatt
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Veteran
Iron
Petar
Telerik team
Share this question
or