title: How do you upload a file to a pre-signed POST URL from a browser to Minio or S3 using javascript
body: <p><a href="https://aws.amazon.com/articles/1434/" rel="nofollow noreferrer">This article</a> shows how to upload a file to Amazon S3 or minio using a form.  I want to use the pre-signed POST URL policy method, since it appears to be the most secure.</p>
  
  <p>However, I wish to upload a file programmatically to minio or S3 using a browser.  In other words, I want to use javascript, not a form.</p>
  
  <p>I'm a node user and familiar with <a href="https://visionmedia.github.io/superagent/#multipart-requests" rel="nofollow noreferrer">superagent</a>, which is very simple to use using the <code>.field()</code> and <code>.attach()</code> operation to set the form fields and to upload the file. </p>
  
  <p>This works in node:</p>
  
  <pre><code>  let cdnAgent = superagent;
    let req = cdnAgent.post(r.data.pictureSet.uploadLink);
    _.each(uploadForm, function(value, key) {
      req.field(key, value);
    });
    // upload file via the created signed policy
    return req
    .set('Content-Type', 'application/octet-stream')
    .attach('file', 'test/data/test.jpg');
  }).then(r =&gt; {
  </code></pre>
  
  <p>However, this does not work in a browser, <code>.attach()</code> is not supported, and when I worked around that, I ran into CORS issues since my javascript domain is a separate domain from my minio or S3 domain.</p>
  
  <p>To answer this question I'd like to see a complete example using XMLHttpRequest, Axios, superagent, or Fetch, that works across domains.</p>
  
  <p>I note there are some similar questions to this and some answers, but they all appear to be very outdated and technology has moved on. So I don't think this is a duplicate question.</p>