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

How to receive a file selected in webapi.net from KendoUI (Upload-AngularJS)

7 Answers 690 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Ever
Top achievements
Rank 1
Ever asked on 07 Jan 2015, 11:02 PM
I am using KendoUI (upload) and I am trying to receive a file in a method in webapi from Kendo UI (upload) but the object received is null.
 
In the Index.cshtml



In webapi:
SaveController.cs



Please, I need an example for this situation. Thanks.








7 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 08 Jan 2015, 09:50 AM

Hello Ever,

The sample code is missing from the post, could you please post it again? In general the WebAPI will not automatically decode multi-part form data requests, so it is up to the developer to achieve this.

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
Ever
Top achievements
Rank 1
answered on 08 Jan 2015, 05:18 PM
Hello Dimiter,

I understand it, I would like to show you the example and my situation.

In the Index.cshtml

            <input type="file" name="files"
                    kendo-upload k-async="{ saveUrl: 'http://localhost:25193/api/Save', 
                                                             removeUrl: 'http://localhost:25193/api/remove/remove', autoUpload: true }"
                    k-select="onFileSelect"
                    k-multiple="false"
                    k-upload="onFileUpload" />

In webapi:
SaveController.cs

[HttpPost]
[HttpOptions]
public HttpResponseMessage Save(HttpPostedFileBase file)
{
    if (file != null) //This object is received Null
               {
       return Request.CreateResponse(HttpStatusCode.OK);
    }
    else
    {
       return Request.CreateResponse(HttpStatusCode.NotFound);
    }
}


1- When I specify (in the upload KendoUI) to call the webapi. In the webapi, the object (file sent from upload KendoUI) received is null.
2- When I specify (in the upload Kendo UI) to call an action in the Controller in the project MVC (Visual Studio). The object received in the action is not null, it is ok.

I would like to know your advice. Thanks.

​
0
Dimiter Madjarov
Telerik team
answered on 09 Jan 2015, 09:59 AM

Hello Ever,

This is what I tried to explain in my previous post - the request won't be resolved automatically as an HttpPostedFileBase and this is up to the developer when uploading files to WebAPI. The complete approach is described on the following page, which also includes an example.

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
Ever
Top achievements
Rank 1
answered on 09 Jan 2015, 04:17 PM
Dimiter, thanks for help me out. I am going to check this link.
0
Dimiter Madjarov
Telerik team
answered on 12 Jan 2015, 08:25 AM

Hello Ever,

Thank you for the update. Have a great day!

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
Murali
Top achievements
Rank 1
answered on 18 Oct 2016, 06:26 PM
Hello Ever, I have the same issue, did you find a solution for this? HttpPostedFileBase this is the model I am using the API controller to receive the file but I see the file object is always null. Please let me know if you have any solution for this. Thanks.
0
Dimiter Madjarov
Telerik team
answered on 19 Oct 2016, 05:46 AM

Hello Murali,

As stated previously, the request won't be resolved automatically as an HttpPostedFileBase. An example approach to achieve this is demonstrated on the following page.

Regards,
Dimiter Madjarov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Upload
Asked by
Ever
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Ever
Top achievements
Rank 1
Murali
Top achievements
Rank 1
Share this question
or