Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2009
    Location
    Atlantis
    Posts
    167

    Upload API video error 204 No Content

    I've been going over and over the Upload API video most of today and I cannot figure out why I am getting a "content 204" in postman and also the timestamp, version and file are all Null within my database. What would cause the data to be sent to but not returned ?

    Click image for larger version. 

Name:	Null Database.png 
Views:	191 
Size:	8.0 KB 
ID:	74325

  2. #2
    Join Date
    Dec 2009
    Location
    Atlantis
    Posts
    167
    Im still having trouble with this giving a 204 no Content error. At 48:11 in the video Nelson says to make sure that the uploads folder is added to the "cs proj" would this be what is causeing the error? how do I check that the uploads folder is infact added to the cs proj ?

  3. #3
    Join Date
    Mar 2004
    Location
    Anacortes, WA
    Posts
    4,168
    That's odd.

    A 204 is actually a success message - what it means is that the server didn't return any response, but otherwise didn't indicate there was a problem. Also, the NULL line in MySQL Workbench indicate that there are no rows. The last row in a table shows up as all NULL - it's actually not a row that exists, but a row that you can add by clicking on one of the fields. What this indicates to me is that no data is being saved to your database.

    What *could* be happening is that your request is erroring out because the folder doesn't exist. That would be strange to me though, since if it was you should be receiving a 500 error - not a 204.

    One way to figure it out would be to start the application in debug mode (F5) and then perform the request via postman. If there was an exception anywhere in the request, the entire thing should break execution and pause - telling you what's wrong. If that doesn't work, try stepping though the entire request by setting a breakpoint in the controller action. Then hit F10/F11 and step though the entire execution, noting anything that's off. The first thing to look at would be to inspect the request parameter variables by hovering your mouse over them, so you can see if they're being populated or not.

    Either way though, you should have the uploads folder. Whenever I say "csproj" I'm referring to the C# project. csproj is the file extension of C# projects in Visual Studio (as sln is the extension for the whole solution file - so if I say "sln" [I pronounce it slinn] I'm referring to the entire solution). So by adding the folder to the csproj, I mean to create a folder (in the solution explorer so it's added to the project).
    Need any help? Feel free to PM me - or send an email directly to nelson@3dbuzz.com!

  4. #4
    Join Date
    Dec 2009
    Location
    Atlantis
    Posts
    167
    Thanks for reply Nelson


    I went back over the videos starting from the Web API video upto the Upload API, this time I now get a response of "404 not found" If I type the address "http://localhost:37027/api/v1/clients/latest" or "http://localhost:37027/api/v1/clients/upload" into post man I get a 404, I also get the 404 error if I type either of these address into the browser. This is confusing me as both addresses "http://localhost:37027/api/v1/launchers/latest" and "http://localhost:37027/api/v1/launchers/upload" work fine both in postman and the browser, I understand that physical path cannot be found but I don't understand why any ideas where to proceed from here?

  5. #5
    Join Date
    Mar 2004
    Location
    Anacortes, WA
    Posts
    4,168
    Quote Originally Posted by blacklisted View Post
    Thanks for reply Nelson


    I went back over the videos starting from the Web API video upto the Upload API, this time I now get a response of "404 not found" If I type the address "http://localhost:37027/api/v1/clients/latest" or "http://localhost:37027/api/v1/clients/upload" into post man I get a 404, I also get the 404 error if I type either of these address into the browser. This is confusing me as both addresses "http://localhost:37027/api/v1/launchers/latest" and "http://localhost:37027/api/v1/launchers/upload" work fine both in postman and the browser, I understand that physical path cannot be found but I don't understand why any ideas where to proceed from here?
    Hm - try double checking your naming on your RoutePrefix and Route attributes in your clients controller. Also make sure it's in the right namespace, and that the controller name ends with "Controller." It should exist as a sibling to your launchers controller class as far as namespaces go.
    Need any help? Feel free to PM me - or send an email directly to nelson@3dbuzz.com!

  6. #6
    Join Date
    Dec 2009
    Location
    Atlantis
    Posts
    167
    Thanks again Nelson for lending a hand. I did double check those before and couldn't see anything wrong.

    The Code in both the Client and Launcher files look OK as well as the Hierarchy in the solution explorer. I am using Microsoft.ASP.NET Web API 2.2 could there maybe have been a change in how the route prefix is handled between 2.1 and 2.2?

    Client Class

    Code:
    using System.Net.Http;
    using System.Threading.Tasks;
    using System.Web.Http;
    using DystopiaOnline.Data;
    using DystopiaOnline.Data.Entities;
    using DystopiaOnline.Web.Infrastructure;
    
    namespace DystopiaOnline.Web.Controllers.Api.V1
    {
        [RoutePrefix("api/v1/clients")]
        public class ClientController : ApiController
        {
            private readonly MMODatabaseContext _database = new MMODatabaseContext();
    
    
            [Route("latest"), HttpGet]
            public object GetLatestClient()
            {
                return new {};
            }
    
    
            [Route("upload"), HttpPost, AuthorizeDeployToken]
            public async Task<IHttpActionResult> UploadClient()
            {
                if (!Request.Content.IsMimeMultipartContent())
                    return BadRequest();
    
    
                return await UploadService.Upload(_database, Request, () => new Client());
            }
        }
    }
    Launcher Class

    Code:
    using System.Web.Http;
    using DystopiaOnline.Web.Infrastructure;
    
    namespace DystopiaOnline.Web.Controllers.Api.V1
    {
        [RoutePrefix("api/v1/launchers")]
        public class LauncherController : ApiController
        {
            [Route("latest"), HttpGet]
            public object GetLatestLauncher()
            {
                return new
                {
                    Version = "5",
                    Url = "bleagh"
                };
            }
    
    
            [Route("upload"), HttpPost, AuthorizeDeployToken]
            public void  UploadLauncher()
            {
                
            }
        }
    }
    Global asax

    Code:
    using System.Web.Http;
    using System.Web.Mvc;
    using System.Web.Optimization;
    using System.Web.Routing;
    
    
    namespace DystopiaOnline.Web
    {
        public class MvcApplication : System.Web.HttpApplication
        {
            protected void Application_Start()
            {
                GlobalConfiguration.Configure(WebApiConfig.Configure);
    
    
                BundleConfig.RegisterBundles(BundleTable.Bundles);
                AreaRegistration.RegisterAllAreas();
                RouteConfig.RegisterRoutes(RouteTable.Routes);
            }
        }
    }
    WebApiConfig

    Code:
    using System.Web.Http;
    
    
    namespace DystopiaOnline.Web
    {
        public static class WebApiConfig
        {
            public static void Configure(HttpConfiguration configuration)
            {
                configuration.MapHttpAttributeRoutes();
                //configuration.Routes.MapHttpRoute("ApiDefault", "api/v1/{controller}/{id}", new{id = RouteParameter.Optional});
            }
        }
    }
    Click image for larger version. 

Name:	Api.png 
Views:	146 
Size:	9.4 KB 
ID:	74338
    Last edited by GreyWalker; 11-07-2014 at 05:24 PM.

  7. #7
    Join Date
    Mar 2004
    Location
    Anacortes, WA
    Posts
    4,168
    Quote Originally Posted by blacklisted View Post
    Thanks again Nelson for lending a hand. I did double check those before and couldn't see anything wrong.

    The Code in both the Client and Launcher files look OK as well as the Hierarchy in the solution explorer. I am using Microsoft.ASP.NET Web API 2.2 could there maybe have been a change in how the route prefix is handled between 2.1 and 2.2?

    Client Class

    Code:
    using System.Net.Http;
    using System.Threading.Tasks;
    using System.Web.Http;
    using DystopiaOnline.Data;
    using DystopiaOnline.Data.Entities;
    using DystopiaOnline.Web.Infrastructure;
    
    namespace DystopiaOnline.Web.Controllers.Api.V1
    {
        [RoutePrefix("api/v1/clients")]
        public class ClientController : ApiController
        {
            private readonly MMODatabaseContext _database = new MMODatabaseContext();
    
    
            [Route("latest"), HttpGet]
            public object GetLatestClient()
            {
                return new {};
            }
    
    
            [Route("upload"), HttpPost, AuthorizeDeployToken]
            public async Task<IHttpActionResult> UploadClient()
            {
                if (!Request.Content.IsMimeMultipartContent())
                    return BadRequest();
    
    
                return await UploadService.Upload(_database, Request, () => new Client());
            }
        }
    }
    Launcher Class

    Code:
    using System.Web.Http;
    using DystopiaOnline.Web.Infrastructure;
    
    namespace DystopiaOnline.Web.Controllers.Api.V1
    {
        [RoutePrefix("api/v1/launchers")]
        public class LauncherController : ApiController
        {
            [Route("latest"), HttpGet]
            public object GetLatestLauncher()
            {
                return new
                {
                    Version = "5",
                    Url = "bleagh"
                };
            }
    
    
            [Route("upload"), HttpPost, AuthorizeDeployToken]
            public void  UploadLauncher()
            {
                
            }
        }
    }
    Global asax

    Code:
    using System.Web.Http;
    using System.Web.Mvc;
    using System.Web.Optimization;
    using System.Web.Routing;
    
    
    namespace DystopiaOnline.Web
    {
        public class MvcApplication : System.Web.HttpApplication
        {
            protected void Application_Start()
            {
                GlobalConfiguration.Configure(WebApiConfig.Configure);
    
    
                BundleConfig.RegisterBundles(BundleTable.Bundles);
                AreaRegistration.RegisterAllAreas();
                RouteConfig.RegisterRoutes(RouteTable.Routes);
            }
        }
    }
    WebApiConfig

    Code:
    using System.Web.Http;
    
    
    namespace DystopiaOnline.Web
    {
        public static class WebApiConfig
        {
            public static void Configure(HttpConfiguration configuration)
            {
                configuration.MapHttpAttributeRoutes();
                //configuration.Routes.MapHttpRoute("ApiDefault", "api/v1/{controller}/{id}", new{id = RouteParameter.Optional});
            }
        }
    }
    Click image for larger version. 

Name:	Api.png 
Views:	146 
Size:	9.4 KB 
ID:	74338
    They look like they should work.

    This may sound dumb, but try doing a solution clean and rebuild (build -> clean / build -> build).

    Also, try creating another API controller (called Test) and see if you can hit it. Have it only have the following code in it (plus whatever using statements you need):
    Code:
    namespace DystopiaOnline.Web.Controllers.Api.V1
    {
        [RoutePrefix("api/v1/test")]
        public class TestController : ApiController
        {
            [Route("blegh"), HttpGet]
            public object GetLatestLauncher()
            {
                return "hey!";
            }
        }
    }
    Then do a rebuild, and try hitting it at "/api/v1/test/blegh" and see what happens.
    Need any help? Feel free to PM me - or send an email directly to nelson@3dbuzz.com!

  8. #8
    Join Date
    Dec 2009
    Location
    Atlantis
    Posts
    167
    I followed those steps and its working now, not sure where I had went wrong as I did do a few clean and builds....Glitch in the matrix maybe lol. thanks for you help Nelson

  9. #9
    Join Date
    Mar 2016
    Posts
    7
    don't understand what are you talking about ? plz explain, i am new here in this forum also in programming !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •