I'm implementing a file upload component into an Umbraco 6.1.6 MVC website front-end. It uses BlueImp File Upload, connecting to a WebAPI controller to handle the actual upload server-side. I found a project on GitHub which bundles BlueImp File Upload with a Web API controller. It works nicely when run as a stand-alone application and looks simple enough to integrate; code-wise it's just a single controller and a bunch of client-side JavaScript essentially.
In my Umbraco project the equivalent URL would be '/umbraco/api/UploadApi/'. However, this is causing an error because without an action extension to the URL the path '/umbraco/api/UploadApi/' returns a 404 error.
Can anyone see how to hook this up correctly in the context of an Umbraco Web API controller? It just seems that the original solution knows that it's a generic post rather than any other specific action.
I've sorted this now by changing the generic 'post', 'put' and 'get' actions in the controller into more standard methods which have to be explicitly called. e.g:
Was:
public HttpResponseMessage Get()
{
if (!string.IsNullOrEmpty(HttpContext.Current.Request["f"]))
{
return DownloadFileContent();
}
return DownloadFileList();
}
Now:
[System.Web.Http.AcceptVerbs("GET")]
[System.Web.Http.HttpGet]
public HttpResponseMessage GetFiles()
{
if (!string.IsNullOrEmpty(HttpContext.Current.Request["f"]))
{
return DownloadFileContent();
}
return DownloadFileList();
}
However, I'm wondering if this is the correct approach or whether there's a way to get the Umbraco Web API controller to automatically route these kinds of actions, as seems to be the case with a 'vanilla' Web API controller?
If anyone knows, I'd be interested to hear, although for the time being the above works.
Calling WebAPI without action URL extension
Hi,
I'm implementing a file upload component into an Umbraco 6.1.6 MVC website front-end. It uses BlueImp File Upload, connecting to a WebAPI controller to handle the actual upload server-side. I found a project on GitHub which bundles BlueImp File Upload with a Web API controller. It works nicely when run as a stand-alone application and looks simple enough to integrate; code-wise it's just a single controller and a bunch of client-side JavaScript essentially.
I've set up an Umbraco Web API controller in my web solution, based on the GitHub project (the controller code is here: https://github.com/bUKaneer/bluimp-jquery-file-upload-with-mvc4-and-webapi/blob/master/solution/BluImpJqueryFileUploadMVC4/ApiControllers/Upload.cs). However, I'm confused by something. The JavaScript posts to the API controller but it doesn't post to any particular action on that controller, so the URL it posts to is 'api/Upload/'.
In my Umbraco project the equivalent URL would be '/umbraco/api/UploadApi/'. However, this is causing an error because without an action extension to the URL the path '/umbraco/api/UploadApi/' returns a 404 error.
Can anyone see how to hook this up correctly in the context of an Umbraco Web API controller? It just seems that the original solution knows that it's a generic post rather than any other specific action.
Thanks for any pointers folks!
I've sorted this now by changing the generic 'post', 'put' and 'get' actions in the controller into more standard methods which have to be explicitly called. e.g:
Was:
Now:
However, I'm wondering if this is the correct approach or whether there's a way to get the Umbraco Web API controller to automatically route these kinds of actions, as seems to be the case with a 'vanilla' Web API controller?
If anyone knows, I'd be interested to hear, although for the time being the above works.
is working on a reply...