I am trying to create an image upload API. I am new to MVC, so I'm not sure exactly how it all works.
I setup the following server-side code, saved in the App_Code folder:
namespace My.Controllers
{
[Umbraco.Web.Mvc.PluginController("My")]
public class NewsletterImageUploadAPIController : UmbracoAuthorizedJsonController
{
public string UploadImage(HttpPostedFileBase file)
{
file.SaveAs(HttpContext.Current.Request.PhysicalApplicationPath + "media/websubscriptions/newsletterimages/" + file.FileName);
return a json object
}
}
}
My intent is to return a json value, but I don't exactly know how to do that. But that's not my biggest problem. I am calling this API from TinyMCE 5 with the following initialization:
The routing seems to work just fine. Unfortunately, when I try to upload an image, I get a 415 error, Unsupported Media Type. And I don't have any idea how to resolve it.
I was able to find a bit more error information on this. It said that the HTTPPostedFileBase couldn't handle the multipart form data. So I removed it and requested the files directly with Request:
public string UploadImage()
{
var file = HttpContext.Current.Request.Files;
//file.SaveAs(HttpContext.Current.Request.PhysicalApplicationPath + "media/websubscriptions/newsletterimages/" + file.FileName);
//return a json object
return null;
}
Now, I am getting a 417 error: Missing token. Does anyone know how to solve that?
Image Upload API
I am trying to create an image upload API. I am new to MVC, so I'm not sure exactly how it all works.
I setup the following server-side code, saved in the App_Code folder:
My intent is to return a json value, but I don't exactly know how to do that. But that's not my biggest problem. I am calling this API from TinyMCE 5 with the following initialization:
The routing seems to work just fine. Unfortunately, when I try to upload an image, I get a 415 error, Unsupported Media Type. And I don't have any idea how to resolve it.
Does anyone have any ideas?
I was able to find a bit more error information on this. It said that the HTTPPostedFileBase couldn't handle the multipart form data. So I removed it and requested the files directly with Request:
Now, I am getting a 417 error: Missing token. Does anyone know how to solve that?
I changed "UmbracoAuthorizedJsonController" to "UmbracoAuthorizedApiControl" and it worked.
is working on a reply...