<commit_before># @title Examples in the Browser

# Examples in the Browser

All of these examples assume that the AWS library is loaded, configured,
and authenticated with the correct credentials.

The common preamble code can be summarized as follows:

    <script src="https://sdk.amazonaws.com/js/aws-sdk-2.0.17.min.js"></script>
    <script type="text/javascript">
      // See the Configuring section to configure credentials in the SDK
      AWS.config.credentials = ...;

      // Configure your region
      AWS.config.region = 'us-west-2';
    </script>

## Basic Usage Example

The following example shows basic usage of the SDK to list objects in an
Amazon S3 bucket:

    <div id="status"></div>
    <ul id="objects"></ul>

    <script type="text/javascript">
      var bucket = new AWS.S3({params: {Bucket: 'myBucket'}});
      bucket.listObjects(function (err, data) {
        if (err) {
          document.getElementById('status').innerHTML =
            'Could not load objects from S3';
        } else {
          document.getElementById('status').innerHTML =
            'Loaded ' + data.Contents.length + ' items from S3';
          for (var i = 0; i < data.Contents.length; i++) {
            document.getElementById('objects').innerHTML +=
              '<li>' + data.Contents[i].Key + '</li>';
          }
        }
      });
    </script>

## Amazon S3

### Uploading data into an object

The following example will upload the contents of a `<textarea>` tag to an
object in S3:

    <textarea id="data"></textarea>
    <button id="upload-button">Upload to S3</button>
    <div id="results"></div>

    <script type="text/javascript">
      var bucket = new AWS.S3({params: {Bucket: 'myBucket'}});

      var textarea = document.getElementById('data');
      var button = document.getElementById('upload-button');
      var results = document.getElementById('results');
      button.addEventListener('click', function() {
        results.innerHTML = '';

        var params = {Key: 'data.txt', Body: textarea.value};
        s3.putObject(params, function (err, data) {
          results.innerHTML = err ? 'ERROR!' : 'SAVED.';
        });
      }, false);
    </script>

### Uploading a local file using the File API

The following example uses the [HTML5 File API](http://www.w3.org/TR/FileAPI/)
to upload a file on disk to S3:

    <input type="file" id="file-chooser" /> 
    <button id="upload-button">Upload to S3</button>
    <div id="results"></div>
<commit_msg>Correct S3 putObject example in browser guide<commit_after># @title Examples in the Browser

# Examples in the Browser

All of these examples assume that the AWS library is loaded, configured,
and authenticated with the correct credentials.

The common preamble code can be summarized as follows:

    <script src="https://sdk.amazonaws.com/js/aws-sdk-2.0.17.min.js"></script>
    <script type="text/javascript">
      // See the Configuring section to configure credentials in the SDK
      AWS.config.credentials = ...;

      // Configure your region
      AWS.config.region = 'us-west-2';
    </script>

## Basic Usage Example

The following example shows basic usage of the SDK to list objects in an
Amazon S3 bucket:

    <div id="status"></div>
    <ul id="objects"></ul>

    <script type="text/javascript">
      var bucket = new AWS.S3({params: {Bucket: 'myBucket'}});
      bucket.listObjects(function (err, data) {
        if (err) {
          document.getElementById('status').innerHTML =
            'Could not load objects from S3';
        } else {
          document.getElementById('status').innerHTML =
            'Loaded ' + data.Contents.length + ' items from S3';
          for (var i = 0; i < data.Contents.length; i++) {
            document.getElementById('objects').innerHTML +=
              '<li>' + data.Contents[i].Key + '</li>';
          }
        }
      });
    </script>

## Amazon S3

### Uploading data into an object

The following example will upload the contents of a `<textarea>` tag to an
object in S3:

    <textarea id="data"></textarea>
    <button id="upload-button">Upload to S3</button>
    <div id="results"></div>

    <script type="text/javascript">
      var bucket = new AWS.S3({params: {Bucket: 'myBucket'}});

      var textarea = document.getElementById('data');
      var button = document.getElementById('upload-button');
      var results = document.getElementById('results');
      button.addEventListener('click', function() {
        results.innerHTML = '';

        var params = {Key: 'data.txt', Body: textarea.value};
        bucket.putObject(params, function (err, data) {
          results.innerHTML = err ? 'ERROR!' : 'SAVED.';
        });
      }, false);
    </script>

### Uploading a local file using the File API

The following example uses the [HTML5 File API](http://www.w3.org/TR/FileAPI/)
to upload a file on disk to S3:

    <input type="file" id="file-chooser" /> 
    <button id="upload-button">Upload to S3</button>
    <div id="results"></div>

{'fraction_non_alphanumeric': 0.13875598086124402, 'fraction_numerical': 0.007575757575757576, 'mean_word_length': 2.7921390778533635, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 55, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6064606', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1407, 'n_words': 448}