title: How do I convert this form to send using XHR in AngularJS
body: <p>I can submit an image to my s3 bucket with this form. I would like to know how to accomplish the same using XMLHTTPRequest and FormData. This is inside an AngularJS app.</p>
  
  <p>This works</p>
  
  <pre><code>&lt;form action="https://abucket.s3.amazonaws.com/" enctype="multipart/form-data" id="the-form" method="post"&gt;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
  &lt;input id="file" name="key" type="hidden" value="raw/${filename}" /&gt;                                                                                                                                      
  &lt;input id="image_uploader_aws_access_key_id" name="AWSAccessKeyId" type="hidden"     value="ABC" /&gt;
  &lt;input id="image_uploader_acl" name="acl" type="hidden" value="public-read" /&gt;
  &lt;input id="image_uploader_policy" name="policy" type="hidden" value="MYBASE64POLICY" /&gt; 
  &lt;input id="image_uploader_signature" name="signature" type="hidden" value="MYSIG" /&gt;                                                                                                                      
  &lt;input id="image_uploader_image" name="file" type="file" /&gt;                                                                                                                                           
  &lt;input name="commit" type="submit" value="Upload" /&gt;                                                                                                                                                                                                                                                                   
  </code></pre>
  
  <p>     </p>
  
  <p>How to make this work - getting 400 Bad Request</p>
  
  <pre><code>var xhr = new XMLHttpRequest();                                                                                                                                                                   
  xhr.open('POST', 'https://abucket.s3.amazonaws.com', true);                                                                                                                                   
  var fd = new FormData();                                                                                                                                                                          
  fd.append('file', file);                                                                                                                                                                          
  fd.append('key', 'raw/${filename}');                                                                                                                                                              
  fd.append('AWSAccessKeyId', 'MYAWSKEY');                                                                                                                                             
  fd.append('acl', 'public-read');                                                                                                                                                                  
  fd.append('success_action_redirect', "https://abc.com/upload_success")                                                                                                        
  fd.append('policy', "MYBASE64POLICY")                                                                                                                                                                   
  fd.append('signature',"MYSIG");                                                                                                                                            
  fd.append('Content-Type', undefined);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  xhr.send(fd);   
  </code></pre>