Question: All,
I tried to use S3 temporary Javascript SDK to upload file to S3, but to be honest,I can not find out any working sample for this, including S3 documentation.

Ideally, I should be able to do this:

s3Client = new AWS.client(new TemporaryCredential( keyId, accesskey, token ));

But I check the documentation, no place is mentioning how to use the temporary credentials to create S3 client.

Our company is already having the api to get temporary credentials, so I am really interested in knowing how to do this in javascript.

I don't know if there are js equivelant solution to below java code:

```
BasicSessionCredentials sessionCredentials = new BasicSessionCredentials(
   session_creds.getAccessKeyId(),
   session_creds.getSecretAccessKey(),
   session_creds.getSessionToken());

AmazonS3 s3 = AmazonS3ClientBuilder.standard()
                        .withCredentials(new AWSStaticCredentialsProvider(sessionCredentials)
                        .build();

```

Thanks for your suggestion.

Answer: 
The TemporaryCredential is just a regular credential, you can use it like the normal way.

```
AWS.config.update({
    region: "us-east-1",
    credentials: new AWS.Credentials('AccessKeyId', 'SecretAccessKey', 'SessionToken')
});

var s3 = new AWS.S3();
var params = {
    Body: "The quick brown fox jumps over the lazy dog",
    Bucket: "example-bucket",
    Key: "hello.txt"
};
s3.putObject(params, function (err, data) {
    if (err) console.log(err, err.stack);
    else console.log(data);
});

```

But what I suggest is using [Pre-Signed URL](http://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObjectJavaSDK.html) to upload file instead of STS TemporaryCredential.

> 
> The pre-signed URLs are useful if you want your user/customer to be
>  able upload a specific object to your bucket, but you don't require
>  them to have AWS security credentials or permissions. 
> 
> 
> -- [AWS Documentation](http://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObject.html)
> 
> 
> 

The client(browser) need not to load the heavy AWS SDK, A simple HTTP PUT request is all.

```
var url = 'https://example-bucket.s3.amazonaws.com/hello.txt?blablabla'
var request = new Request(url, {
    method: 'PUT',
    body: "The quick brown fox jumps over the lazy dog",
});
fetch(request).then(function (response) {
    console.log(response);
}).catch(function (err) {
    console.log(err, err.stack);
});

```
Here is the complete example on how to read, upload, list, delete photo albums to S3.

<http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photo-album.html>

```
AWS.config.update({
  region: bucketRegion,
  credentials: new AWS.CognitoIdentityCredentials({
    IdentityPoolId: IdentityPoolId
  })
});

```

If your company already has a way to get temporary credentials, replace the above credentials object with your credentials and rest of them is the same.

Thanks.