title: Uploading to Amazon S3 via ng-file-upload; Error 400
body: <p>I am using <a href="https://github.com/danialfarid/ng-file-upload" rel="nofollow">ng-file-upload</a> to upload a photo to S3. I have tested my S3 bucket and my policy/signature generator with the ng-file-upload <a href="https://angular-file-upload.appspot.com/" rel="nofollow">demo tool</a> and have successfully used it to upload the photo to my bucket.</p>
  
  <hr>
  
  <p><em>Edit:</em> A key difference seems to be the addition of a header: </p>
  
  <p><code>Authorization:Token 3j4fl8jk0lqfkj4izj2w3ljfopljlwep1010notreal</code></p>
  
  <p>That is present in my code but not in the demo page. Perhaps it's my angular app.</p>
  
  <hr>
  
  <p>Installed through bower, took the relevant components, tried to upload a file, and get an error that looks like this:</p>
  
  <pre><code> 400: &lt;?xml version="1.0" encoding="UTF-8"?&gt; 
   &lt;Error&gt;
   &lt;Code&gt;InvalidArgument&lt;/Code&gt; 
   &lt;Message&gt;Unsupported Authorization Type&lt;/Message&gt; 
   &lt;ArgumentName&gt;Authorization&lt;/ArgumentName&gt;
   &lt;ArgumentValue&gt;Token 3j4fl8jk0lqfkj4izj2w3ljfopljlwep1010notreal&lt;/ArgumentValue&gt;
   &lt;RequestId&gt;F1F5FK-not-real-81FED9CA&lt;/RequestId&gt;
   &lt;HostId&gt;CQEW98p3D2e+pVz-not-real-codeu28m7asqpGjagL3409gj3f4kijKJpofk&lt;/HostId&gt;
   &lt;/Error&gt;
  </code></pre>
  
  <p>Searching around, I've noted many 400 Errors but not many cases with the <code>ArgumentValue</code> as <code>Token [some-code-here]</code>. </p>
  
  <p>Looking at <a href="http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html" rel="nofollow">AWS documentation</a>, <code>InvalidArgument</code> is a bit opaque for someone rather new to AWS. </p>
  
  <p>And here is the policy that I'm encoding (Python):</p>
  
  <pre><code>#exptime = '2100-07-31T06:23:35Z' #for debugging
  policy_document = {"expiration": exptime,
      "conditions": [ 
        {"bucket": settings.AWS_STORAGE_BUCKET_NAME}, 
        ["starts-with", '$key', ""],
        {"acl": "private"},
        ["starts-with", "$Content-Type", ""],
        ["starts-with", "$filename", ""],
        ["content-length-range", 0, 5000000] 
      ]
    }
  </code></pre>
  
  <p>To reiterate, this policy with the aforementioned demo worked, so I expect a problem on my front-end implementation:</p>
  
  <pre><code>$scope.upload = function(file) {
      file.upload = Upload.upload({
                  url: 'https://mybucket.s3-us-west-2.amazonaws.com',
                  method: 'POST',
                  fields: {
                      key: file.name,
                      AWSAccessKeyId: myAccessKeyId,
                      acl: 'private',
                      policy: myPolicyEncoded,
                      signature: mySignatureEncoded,
                      "Content-Type": file.type === null || 
                          file.type === '' ? 'application/octet-stream' : file.type,
                      filename: file.name
                  },
                  file: file
              });
  }
  </code></pre>