

We create also a class that implements that interface and we call it ApiService. In our shared Project of the Xamarin.Forms app we create a new interface called IApiService that representes the capabilites of our web service. This variable is assisgned automatically by ASP.NET if the model binding finds a correct match in the request from the client. The IFormFile file parameter represents the uploaded file. The upload of the image is implemented in the Post method. Using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create)) Var uploads = Path.Combine(_environment.WebRootPath, "uploads") _environment = environment ? throw new ArgumentNullException(nameof(environment))

Public ImageController(IHostingEnvironment environment) Private readonly IHostingEnvironment _environment Public class ImageController : Controller Now we write this code in the ImageController class: Right click in the Controllers folder, Add -> Controller, we choose empty controller and we give the name ImageController.cs. Now we add a Controller in the Controllers folder to handle our picture upload. NET Core -> ASP.NET Core Web Application, give a name and hit OK. To create a REST service we create an ASP.NET Core Web Application project. You can download the entire solution of this example here. UWP flavor of the upload with file picker

We’ll se how to upload a picture to a RESTful service developed with ASP.NET Core. With this blog post we continue the exploration of Xamarin.Forms.
