How to use the @aws-sdk/client-s3.PutObjectCommand function in @aws-sdk/client-s3

To help you get started, we’ve selected a few @aws-sdk/client-s3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github awsdocs / aws-doc-sdk-examples / javascript / example_code / nodegetstarted / sampleV3.js View on Github external
} = require('@aws-sdk/client-s3')
  
  var uuid = require('uuid')

  // Unique bucket name
  const bucketName = 'node-sdk-sample-' + uuid.v4()
  // Name for uploaded object
  const keyName = 'hello_world.txt'

  const client = new S3Client({})

  const createCommand = new CreateBucketCommand({
    Bucket: bucketName
  })

  const putCommand = new PutObjectCommand({
    Bucket: bucketName,
    Key: keyName,
    Body: 'Hello World!'
  })

  try {
    await client.send(createCommand)
    await client.send(putCommand)
    console.log('Successfully uploaded data to ' + bucketName + '/' + keyName)
  } catch (err) {
    console.error(err, err.stack)
  }
})()
// snippet-end:[s3.js.create_unique_bucket]

@aws-sdk/client-s3

AWS SDK for JavaScript S3 Client for Node.js, Browser and React Native

Apache-2.0
Latest version published 3 days ago

Package Health Score

100 / 100
Full package analysis

Similar packages