title: Uploading an Image to Amazon S3 using ASP.Net MVC 3
body: <p>I am having an issue on the controller side using ASP.Net MVC 3 trying to upload an image to amazon s3. Here is what I have and the error.</p>
  
  <p><strong>Here is my HTML form.</strong></p>
  
  <pre><code>@using (Html.BeginForm())
  {
      &lt;div class="in forms"&gt;
  
          &lt;input type="file" id="file" name="file" class="box" /&gt;&lt;/p&gt;
  
          &lt;p&gt;&lt;input type="submit" value="Upload" id="btnSubmit" class="com_btn" /&gt;&lt;/p&gt;
  
  }
  </code></pre>
  
  <p><strong>And here is the code in my controller</strong></p>
  
  <pre><code>[HttpPost]
      public ActionResult Index(HttpPostedFileBase file)
      {
          AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client("*redacted*","*redacted*");
          if (file.ContentLength &gt; 0)
          {
              var request = new PutObjectRequest();
              request.WithBucketName("*redacted*");
              request.WithKey(file.FileName);
              request.FilePath = Path.GetFullPath(file.FileName);
              request.ContentType = file.ContentType;
              request.StorageClass = S3StorageClass.ReducedRedundancy;
              request.CannedACL = S3CannedACL.PublicRead;
              client.PutObject(request);
              return Redirect("UploadSuccess");
          }
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p><strong>The error I am getting is.</strong></p>
  
  <p>Server Error in '/' Application.</p>
  
  <p>Object reference not set to an instance of an object.</p>
  
  <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.</p>
  
  <p>Source Error:</p>
  
  <p>Line 28: if (file.ContentLength > 0)</p>