title: How to get and use temporary security credentials for multipart upload with javascript aws-sdk addressing MinIO server?
body: <p>I have a MinIO server and need to write a simple web application that selects a file and performs a multipart upload with temporary security credentials. I would like to do something like described here: <a href="https://github.com/minio/minio/blob/master/docs/sts/assume-role.md" rel="nofollow noreferrer">https://github.com/minio/minio/blob/master/docs/sts/assume-role.md</a> for getting temporary security credentials using some user credentials i created before. But i want to do it using aws-sdk-js. And i am not sure how to do that for MinIO, like pointing to the right endpoint and using the existing user credentials to invoke AssumeRole or some other corresponding function. Afterwards i want to do a multipartupload, with which i am also struggling how to use it.</p>
  
  <p>I have gone through documentation, but i am struggling to use the provided functions with MinIO in the way i want.</p>
  
  <p>AssumeRole: <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/STS.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/STS.html</a></p>
  
  <p>Multipart Upload: <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3/ManagedUpload.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3/ManagedUpload.html</a></p>
  
  <p>I already set up some code to show what i want to do. multipart-upload.js creates a express server that exposes and endpoint for clients to retrieve temporary security credentials, such that i don't have to share any long-term credentials with the client.</p>
  
  <p>multipart-upload.js</p>
  
  <pre><code>const AWS = require('aws-sdk')
  
  var sts = new AWS.STS();
  
  const server = require('express')()
  
  server.get('/openTemporarySession', (req, res) =&gt; {
      var params = {
        DurationSeconds: 'NUMBER_VALUE',
        SerialNumber: 'STRING_VALUE',
        TokenCode: 'STRING_VALUE'
      };
      sts.getSessionToken(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else     res.send(data);           // successful response
      })
  })
  
  server.get('/', (req, res) =&gt; {
      res.sendFile(__dirname + '/indexmultipart.html');
  })
  
  server.listen(8080)
  </code></pre>
  
  <p>The client selects files and uploads them through a button. The corresponding function gets temporary security credentials from the server and sequentially performs multipart upload.</p>
  
  <p>indexmultipart.html</p>
  
  <pre><code>&lt;input type="file" id="selector" multiple&gt;
  &lt;button onclick="upload()"&gt;Upload with minio&lt;/button&gt;
  
  &lt;div id="status"&gt;No uploads&lt;/div&gt;
  
  &lt;script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.12.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
    var sts = new AWS.STS();
  
    // invoke helper function to get temporary security credentials and perform multipart upload
    function upload() {
      // Reset status text on every upload.
      $('#status').text(`No uploads`)
      retrieveTempCredentials()
      // Get selected files from the input element.
      var files = $("#selector")[0].files
      for (var i = 0; i &lt; files.length; i++) {
        var file = files[i]
        uploadFile(file)
      }
    }
  
    // call endpoint to generate a pre-signed URL for use in uploading file. 
    function retrieveTempCredentials() {
      $.get(`/openTemporarySession`, (data) =&gt; {
        AWS.config.credentials = sts.credentialsFrom(data);
      })
    }
  
    // upload file to MinIO using the presigned url
    function uploadFile(file) {
      var upload = new AWS.S3.ManagedUpload({
        params: {Bucket: 'bucket', Key: 'key', Body: file},
        tags: [{Key: 'tag1', Value: 'value1'}, {Key: 'tag2', Value: 'value2'}]
      });
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>This code does not really work and I need some help to achieve something like this since i am all new to javascript and html.</p>