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

8 posts, 0 answers
  1. Ever
    Ever avatar
    8 posts
    Member since:
    Nov 2014

    Posted 07 Jan 2015 Link to this post

    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.








  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 08 Jan 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Ever
    Ever avatar
    8 posts
    Member since:
    Nov 2014

    Posted 08 Jan 2015 in reply to Dimiter Madjarov Link to this post

    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.

  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 09 Jan 2015 Link to this post

    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!
     
  6. Ever
    Ever avatar
    8 posts
    Member since:
    Nov 2014

    Posted 09 Jan 2015 in reply to Dimiter Madjarov Link to this post

    Dimiter, thanks for help me out. I am going to check this link.
  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 12 Jan 2015 Link to this post

    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!
     
  8. Murali
    Murali avatar
    5 posts
    Member since:
    Jun 2016

    Posted 18 Oct in reply to Ever Link to this post

    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.
  9. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 19 Oct Link to this post

    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.
     
Back to Top
Kendo UI is VS 2017 Ready