2 Replies - 222 Views - Last Post: 04 January 2019 - 08:14 AM Rate Topic: -----

#1 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,944
  • Joined: 12-December 12

Kendo upload, Cannot POST

Posted 04 January 2019 - 05:25 AM

I have an ASP.NET Core, Angular application. I am using the Kendo UI Upload component to post a file/image to the server. Here is some configuration:

<input name="files" id="headshotFile" type="file">

        kendo.jQuery('#headshotFile').kendoUpload({
          select: onselectFile,
          async: {
            saveUrl: "/api/Upload/Save",
            removeUrl: "/api/Upload/Remove",
            autoUpload: true
          }
        });

I can see via Fiddler that it does attempt to reach the api when I have selected the file; it does show the URL as /api/upload/save but the only message I get is

Quote

404 Not Found, Cannot POST /api/Upload/Save

I assumed it was just because I was missing the [HttpPost] attribute but I added it and get the same problem:

        [HttpPost]
        public ActionResult Save(IFormFileCollection files)
        {
            // The Name of the Upload component is "files"
            if (files != null)
            {

The controller initial code, for reference, is this:

namespace People.Api
{
    [Route("api/[controller]")]
    [ApiController]
    public class UploadController : Controller
    {
        private IHostingEnvironment _env;

        public UploadController(IHostingEnvironment env)
        {
            _env = env;
        }

I am a bit stumped on how to pursue this further. Do you have any suggestions or an idea of what the problem could be? Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Kendo upload, Cannot POST

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,944
  • Joined: 12-December 12

Re: Kendo upload, Cannot POST

Posted 04 January 2019 - 07:19 AM

It appears there is a mismatch, somehow, between Angular and .NET routing. If I try the location via the addressbar I can see:

Quote

vendor.js:49968 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'api/Upload/Save'
Error: Cannot match any routes. URL Segment: 'api/Upload/Save'
at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirects.noMatchError (vendor.js:70740)

Yet it is odd because, in a service.ts I use this successfully,

  public update(contact: Contact) {
    return this.http.put<ServerResponse<Contact>>(this.contactsUrl + '/' + contact.contactID, contact)
      .pipe(map(res => res)
        //,catchError((err: HttpErrorResponse) => {})
      );
  }

where the contactsUrl is "api". I did try without the initial forward slash to no avail.

I'm still missing something...
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,944
  • Joined: 12-December 12

Re: Kendo upload, Cannot POST

Posted 04 January 2019 - 08:14 AM

Darn, because I was having to fathom out example(s) for earlier versions of Angular and ASP.NET I lost track of the need to identify the Action:

        [HttpPost("Save")]
        public ActionResult Save(IFormFileCollection files)

[The example I had, and had to modify, didn't have HttpPost or IFormFileCollection.]

Anyway, resolved ;)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1