| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
The following tasks guide you through using the Ruby classes to upload a file. The API
provides provides a #write method that can take options
that you can use to specify how to upload your data.
Uploading Objects
1 | Create an instance of the |
2 |
Use the |
The following Ruby code sample demonstrates the preceding tasks and uses the
options hash :file to specify
the path to the file to upload.
s3 = AWS::S3.new # Upload a file. key = File.basename(file_name) s3.buckets[bucket_name].objects[key].write(:file => file_name)
Example
The following Ruby script example uploads a file to an Amazon S3 bucket. For instructions about how to create and test a working sample, see Using the AWS SDK for Ruby.
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
AWS.config(
:access_key_id => '*** Provide your access key ***',
:secret_access_key => '*** Provide your secret key ***'
)
bucket_name = '*** Provide bucket name ***'
file_name = '*** Provide file name ****'
# Get an instance of the S3 interface.
s3 = AWS::S3.new
# Upload a file.
key = File.basename(file_name)
s3.buckets[bucket_name].objects[key].write(:file => file_name)
puts "Uploading file #{file_name} to bucket #{bucket_name}."