title: How to upload an image from Android to asp.net MVC web service
body: <p>I have to do an application that take a picture from my android phone and send it to the asp.net web service MVC.</p>
  
  <p>Here is the controller file <code>HomeController.cs</code>:</p>
  
  <pre><code>public class HomeController : Controller {
      BlobStorageService _blobStorageService = new BlobStorageService();
      public ActionResult Index() {
          return View();
      }
  
      public ActionResult Upload() {
          CloudBlobContainer blobContainer = _blobStorageService.GetCloudBlobContainer();
          List&lt;string&gt; blobs = new List&lt;string&gt;();
          foreach (var blobItem in blobContainer.ListBlobs())
              blobs.Add(blobItem.Uri.ToString());
          return View(blobs);
      }
  
      [HttpPost]
      public ActionResult Upload(HttpPostedFileBase image) {
          if (image.ContentLength &gt; 0) {
              CloudBlobContainer blobContainer = _blobStorageService.GetCloudBlobContainer();
              CloudBlockBlob blob = blobContainer.GetBlockBlobReference(image.FileName);
              blob.UploadFromStream(image.InputStream);
          }
          return RedirectToAction("Upload");
      }
  
      [HttpPost]
      public string DeleteImage(string Name) {
          Uri uri = new Uri(Name);
          string filename = System.IO.Path.GetFileName(uri.LocalPath);
  
          CloudBlobContainer blobContainer = _blobStorageService.GetCloudBlobContainer();
          CloudBlockBlob blob = blobContainer.GetBlockBlobReference(filename);
  
          blob.Delete();
  
          return "File Deleted";
      }
  }
  </code></pre>
  
  <p>and this is the view file <code>Upload.cshtml</code></p>
  
  <pre><code>    @{
      ViewBag.Title = "Upload";
  }
  
  &lt;h2&gt;Upload Image&lt;/h2&gt;
  
  &lt;p&gt;
      @using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) {
          &lt;input type="file" name="image" /&gt;
          &lt;input type="submit" value="Upload" /&gt;
      }
  
  &lt;/p&gt;
  
  &lt;ul style="list-style-type: none; padding:0;"&gt;
      @foreach (var item in Model) {
          &lt;li&gt;
              &lt;img src="@item" alt="images" width="100" height="100" /&gt;
              &lt;a id="@item" href="#" onclick="deleteImage('@item')"&gt;Delete&lt;/a&gt;
  
          &lt;/li&gt;
      }
  
  &lt;/ul&gt;
  
  &lt;script&gt;
      function deleteImage(item) {
          var url = "/Home/DeleteImage";
          $.post(url, { Name: item }, function (data) {
              window.location.href = "/Home/Upload";
              alert(data);
          });
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>What I have to do is to create an android client that is able to do the same things the web client does.</p>