I have a method for my API controller
public class PhotoController : ApiController
{
public IPhotoService _photoService;
public PhotoController()
{
_photoService = new PhotoService();
}
[HttpPost]
[Route("photo/upload/{photo}")]
public bool UploadPicture()
{
try
{
var httpRequest = HttpContext.Current.Request;
JObject param = JObject.Parse(HttpContext.Current.Request.Params["photo"]);
var path = "../" + Utils.RandomGenerator() + Utils.RandomGenerator() + "." + httpRequest.Files[0].FileName.Split('.').Last();
var postedFile = httpRequest.Files[0];
var filePath = HttpContext.Current.Server.MapPath(path);
postedFile.SaveAs(filePath);
_photoService.UploadPhoto(param, path);
return true;
}
catch (Exception ex)
{
return false;
}
}
}
If I remove this block of code
public IPhotoService _photoService;
public PhotoController()
{
_photoService = new PhotoService();
}
it work but whenever I create my service the API method can't work
on client console always print out this error
POST localhost:17699/photo/upload/%7Bphoto%7D 500 (Internal Server Error)
I don't know why because my others API controller can work smooth.
I've searched, cleaned and built project...etc...
Can you guys help me please