Method: AWS::S3::Client#put_object
- Defined in:
- lib/aws/s3/client.rb
#put_object(options = {}) ⇒ Core::Response
Puts data into an object, replacing the current contents.
s3_client.put_object({
:bucket_name => 'bucket-name',
:key => 'readme.txt',
:data => 'This is the readme for ...',
})
Block Form
In block form, this method yields a stream to the block that accepts data chunks. For example:
s3_client.put_object(
:bucket_name => 'mybucket',
:key => 'some/key'
:content_length => File.size('myfile')
) do |buffer|
File.open('myfile') do |io|
buffer.write(io.read(length)) until io.eof?
end
end
This form is useful if you need finer control over how potentially large amounts of data are read from another source before being sent to S3; for example, if you are using a non-blocking IO model and reading from a large file on disk or from another network stream. Some HTTP handlers do not support streaming request bodies, so if you plan to upload large objects using this interface you should make sure the HTTP handler you configure for the client meets your needs.
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 |
# File 'lib/aws/s3/client.rb', line 860 object_method(:put_object, :put, :header_options => { :website_redirect_location => 'x-amz-website-redirect-location', :acl => 'x-amz-acl', :grant_read => 'x-amz-grant-read', :grant_write => 'x-amz-grant-write', :grant_read_acp => 'x-amz-grant-read-acp', :grant_write_acp => 'x-amz-grant-write-acp', :grant_full_control => 'x-amz-grant-full-control', :content_md5 => 'Content-MD5', :cache_control => 'Cache-Control', :content_disposition => 'Content-Disposition', :content_encoding => 'Content-Encoding', :content_type => 'Content-Type', :expires => 'Expires', }) do configure_request do |request, | = () set_body_stream_and_content_length(request, ) request. = [:metadata] request.storage_class = [:storage_class] request.server_side_encryption = [:server_side_encryption] super(request, ) end process_response do |resp| extract_object_headers(resp) end simulate_response do |response| response.data[:etag] = 'abc123' response.data[:version_id] = nil end end |