ruby/example_code/s3/s3-ruby-example-upload-item.rb
# Prerequisites:
#
# - An S3 bucket.
# - An object to upload to the bucket.
#
# @param s3_client [Aws::S3::Client] An initialized S3 client.
# @param bucket_name [String] The name of the bucket.
# @param object_key [String] The name of the object.
# @return [Boolean] true if the object was uploaded; otherwise, false.
# @example
#   exit 1 unless object_uploaded?(
#     Aws::S3::Client.new(region: 'us-west-2'),
#     'doc-example-bucket',
#     'my-file.txt'
#   )

An S3 bucket.
An object to upload to the bucket.
An S3 bucket . An object to upload to the bucket .
def object_uploaded?(s3_client, bucket_name, object_key)
  response = s3_client.put_object(
    bucket: bucket_name,
    body: "c:\\my-file.txt",
    key: object_key
  )
  if response.etag
    return true
  else
    return false
  end
rescue StandardError => e
  puts "Error uploading object: #{e.message}"
  return false
end
def object_uploaded? ( s3_client , bucket_name , object_key ) response = s3_client . put_object ( bucket : bucket_name , body : "c:\\my-file.txt" , key : object_key ) if response . etag return true else return false end rescue StandardError => e puts "Error uploading object: #{e.message}" return false end
Prerequisites:
 An S3 bucket.
Prerequisites : An S3 bucket .
true if the object was uploaded; otherwise, false.
true if the object was uploaded ; otherwise false .
Boolean
s3_client
An initialized S3 client.
An initialized S3 client .
bucket_name
The name of the bucket.
The name of the bucket .
object_key
The name of the object.
The name of the object .
example
exit 1 unless object_uploaded?( Aws::S3::Client.new(region: 'us-west-2'), 'doc-example-bucket', 'my-file.txt' )
exit 1 unless object_uploaded? ( Aws :: S3 :: Client . new ( region : ' us - west - 2 ' ) ' doc - example - bucket ' ' my - file . txt ' )