title: How to upload image to server from xamarin forms app
body: <p>I'm trying to send an image from my xamarin forms application to a asp .net core server using a post request. I need to save the image in some server folder but I can not do it.</p>
  
  <p>This is the method to send the image once I have it selected in _mediaFile</p>
  
  <pre><code>    private async void UploadFile_Clicked(object sender, EventArgs e)
      {
          var uri = new Uri(string.Format(Constants.UsersRestUrl + "/Files/Upload/", string.Empty));
          var content = new MultipartFormDataContent();
  
          content.Add(new StreamContent(_mediaFile.GetStream()),
              "\"file\"",
              $"\"{_mediaFile.Path}\"");
  
          var httpClient = new HttpClient();
          var httpResponseMessage = await httpClient.PostAsync(uri, content);
      }
  </code></pre>
  
  <p>I currently have this in my api controller</p>
  
  <pre><code>    [Route("Files/Upload/")]
      [HttpPost]
      public async Task&lt;IActionResult&gt; Post(IFormFile file)
      {
          Debug.Write("******");
          // full path to file in temp location
          var filePath = Path.GetTempFileName();
          Debug.Write("****** File Path " + filePath);
  
          if (file.Length &gt; 0)
          {
              using (var stream = new FileStream(filePath, FileMode.Create))
              {
                  await file.CopyToAsync(stream);
              }
          }
          return Ok(new { file });
      }
  </code></pre>
  
  <p>I tried to apply this <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads</a> but it is oriented to save the image directly from an asp net core application.
  Can someone help me? Thanks</p>