title: Restrict user to upload a certain type on Azure
body: <p>I am developing a web app, and I want to restrict the user to upload a certain type on the Azure blob for e.g. only images or PDFs only.</p>
  
  <p>Is there a way that when I press the upload Image, it checks whether it is an image or not? If it is not an image it rejects the Request? Better to have the validation at server side</p>
  
  <p>This is the coding I am using:</p>
  
  <pre><code>&lt;div&gt;
      Select Image to upload a ClassDiagram
      &lt;input name="classdiagram" type="file" multiple="multiple" accept="image/*"&gt;
      &lt;input type="submit" value="Upload Image" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Partial Code of public ActionResult ImageUpload()</strong></p>
  
  <pre><code>var dfd = Request.Files["dfd"];
  var classdiagram = Request.Files["classdiagram"];
  // Code hidden for Brevity. Multiple var instances.    
  
  // --- SETTING UP THE CONTAINER --- //
  
  // Create the CloudStorageAccount
  
  StorageCredentials credentials = new StorageCredentials("swiftdevelopmentstorage", "HqaCkZjdQ8w/DX/fS3wDxU6HXbeqV5EZ1b+UQaKALxaJDrN9JoZZYn8Q0KT6QR4tCrdGQicxE+tKRKScjINW8w==");
  CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);
  
  
  CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
  
  // Retrieve Reference to container
  CloudBlobContainer container = blobClient.GetContainerReference("systemdesign");
  
  // Create if nonexistent
  container.CreateIfNotExists();
  
  // Change Default Private Permission to Public
  container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
  
  
  // Depending on the Design type (e.g. Flowchart, dfd..) the blob will be uploaded to a different sub folder
  
  if (dfd != null)
  {
      string uniqueBlobName = string.Format("dfd/image_{0}{1}",
          Guid.NewGuid().ToString(), Path.GetExtension(dfd.FileName));
      CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
  
  // Rest of the code is all other if cases for the remaining Request.Files
  </code></pre>
  
  <p>The problem is that the <code>accept="image/*"</code>, still doesn't deny uploading of other extensions if the users switches to "Show All"</p>