Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

ApiController could not be found

$
0
0

Based on this video image I have add the using System.Web; using System.Web.Http; but i still get the error state that apicontroller could no found, and so on, below picture is the error I face:

below is my code

using System;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Collections.Generic;

namespace UploadToServer.Server.Controllers
{
public class UploadsController : ApiController
{
    [Route("api/Files/Upload")]
    public async Task<string> Post()
    {
        try
        {
            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Files.Count > 0)
            {
                foreach (string file in httpRequest.Files)
                {
                    var postedFile = httpRequest.Files[file];

                    var fileName = postedFile.FileName.Split('\\').LastOrDefault().Split('/').LastOrDefault();

                    var filePath = HttpContext.Current.Server.MapPath("~/Uploads/" + fileName);

                    postedFile.SaveAs(filePath);

                    return "/Uploads/" + fileName;
                }
            }
        }
        catch (Exception exception)
        {
            return exception.Message;
        }

        return "no files";
    }
   }
 }

Anyone can share me ideas?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>