Class: AWS::S3::Client
- Inherits:
-
Core::Client
- Object
- Core::Client
- AWS::S3::Client
- Extended by:
- Validators
- Includes:
- Core::UriEscape, Validators
- Defined in:
- lib/aws/s3/client.rb,
lib/aws/s3/client/xml.rb
Overview
Client class for Amazon Simple Storage Service (S3).
Defined Under Namespace
Modules: Validators
Constant Summary collapse
- API_VERSION =
'2006-03-01'
- XMLNS =
"http://s3.amazonaws.com/doc/#{API_VERSION}/"
Instance Attribute Summary
Attributes inherited from Core::Client
Instance Method Summary collapse
- #abort_multipart_upload(options = {}) ⇒ Core::Response
- #complete_multipart_upload(options = {}) ⇒ Core::Response
-
#copy_object(options = {}) ⇒ Core::Response
Copies an object from one key to another.
-
#create_bucket(options = {}) ⇒ Core::Response
(also: #put_bucket)
Creates a bucket.
-
#delete_bucket(options = {}) ⇒ Core::Response
Deletes an empty bucket.
- #delete_bucket_cors(options = {}) ⇒ Core::Response
- #delete_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response
-
#delete_bucket_policy(options = {}) ⇒ Core::Response
Deletes the access policy for a bucket.
- #delete_bucket_tagging(options = {}) ⇒ Core::Response
- #delete_object(options = {}) ⇒ Core::Response
- #delete_objects(options = {}) ⇒ Core::Response
-
#get_bucket_acl(options = {}) ⇒ Core::Response
Gets the access control list for a bucket.
- #get_bucket_cors(options = {}) ⇒ Core::Response
- #get_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response
-
#get_bucket_location(options = {}) ⇒ Core::Response
Gets the bucket’s location constraint.
-
#get_bucket_policy(options = {}) ⇒ Core::Response
Gets the access policy for a bucket.
- #get_bucket_tagging(options = {}) ⇒ Core::Response
- #get_bucket_versioning(options = {}) ⇒ Core::Response
-
#get_object(options = {}) ⇒ Core::Response
Gets the data for a key.
-
#get_object_acl(options = {}) ⇒ Core::Response
Gets the access control list for an object.
- #head_object(options = {}) ⇒ Core::Response
- #initiate_multipart_upload(options = {}) ⇒ Core::Response
- #list_buckets(options = {}) ⇒ Core::Response
- #list_multipart_uploads(options = {}) ⇒ Core::Response
- #list_object_versions(options = {}) ⇒ Core::Response
- #list_objects(options = {}) ⇒ Core::Response (also: #get_bucket)
- #list_parts(options = {}) ⇒ Core::Response
-
#put_bucket_acl(options = {}) ⇒ Core::Response
(also: #set_bucket_acl)
Sets the access control list for a bucket.
- #put_bucket_cors(options = {}) ⇒ Core::Response
- #put_bucket_tagging(options = {}) ⇒ Core::Response
-
#put_object(options = {}) ⇒ Core::Response
Puts data into an object, replacing the current contents.
-
#put_object_acl(options = {}) ⇒ Core::Response
(also: #set_object_acl)
Sets the access control list for an object.
- #set_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response
-
#set_bucket_policy(options = {}) ⇒ Core::Response
Sets the access policy for a bucket.
- #set_bucket_versioning(options = {}) ⇒ Core::Response
- #upload_part(options = {}) ⇒ Core::Response
Methods included from Validators
dns_compatible_bucket_name?, json_validation_message, path_style_bucket_name?, require_acl!, require_bucket_name!, require_part_number!, require_policy!, require_upload_id!, set_body_stream_and_content_length, valid_bucket_name?, validate!, validate_bucket_name!, validate_key!, validate_parts!
Methods included from Core::UriEscape
Methods inherited from Core::Client
#initialize, #log_warning, #operations, operations, #with_http_handler, #with_options
Constructor Details
This class inherits a constructor from AWS::Core::Client
Instance Method Details
#abort_multipart_upload(options = {}) ⇒ Core::Response
1192 1193 1194 1195 1196 1197 1198 |
# File 'lib/aws/s3/client.rb', line 1192 object_method(:abort_multipart_upload, :delete) do configure_request do |req, | require_upload_id!([:upload_id]) super(req, ) req.add_param('uploadId', [:upload_id]) end end |
#complete_multipart_upload(options = {}) ⇒ Core::Response
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 |
# File 'lib/aws/s3/client.rb', line 1158 object_method(:complete_multipart_upload, :post, XML::CompleteMultipartUpload) do configure_request do |req, | require_upload_id!([:upload_id]) validate_parts!([:parts]) super(req, ) req.add_param('uploadId', [:upload_id]) parts_xml = [:parts].map do |part| "<Part>"+ "<PartNumber>#{part[:part_number].to_i}</PartNumber>"+ "<ETag>#{REXML::Text.normalize(part[:etag].to_s)}</ETag>"+ "</Part>" end.join req.body = "<CompleteMultipartUpload>#{parts_xml}</CompleteMultipartUpload>" end process_response do |response| add_sse_to_response(response) response.data[:version_id] = response.http_response.header('x-amz-version-id') end simulate_response do |response| response.data[:version_id] = nil end end |
#copy_object(options = {}) ⇒ Core::Response
Copies an object from one key to another.
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 |
# File 'lib/aws/s3/client.rb', line 1247 object_method(:copy_object, :put, :header_options => { :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', :copy_source => 'x-amz-copy-source', :cache_control => 'Cache-Control', :metadata_directive => 'x-amz-metadata-directive', :content_type => 'Content-Type', :content_disposition => 'Content-Disposition', }) do configure_request do |req, | validate!(:copy_source, [:copy_source]) do "may not be blank" if [:copy_source].to_s.empty? end = .merge(:copy_source => escape_path([:copy_source])) super(req, ) req. = [:metadata] req.storage_class = [:storage_class] req.server_side_encryption = [:server_side_encryption] if [:version_id] req.headers['x-amz-copy-source'] += "?versionId=#{[:version_id]}" end end process_response do |response| response.data[:version_id] = response.http_response.header('x-amz-version-id') response.data[:etag] = response.http_response.header('ETag') if time = response.http_response.header('Last-Modified') response.data[:last_modified] = Time.parse(time) end add_sse_to_response(response) end end |
#create_bucket(options = {}) ⇒ Core::Response Also known as: put_bucket
Creates a bucket.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/aws/s3/client.rb', line 129 bucket_method(:create_bucket, :put, :header_options => { :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', }) do configure_request do |req, | validate_bucket_name!([:bucket_name]) if location = [:location_constraint] xmlns = "http://s3.amazonaws.com/doc/#{API_VERSION}/" req.body = <<-XML <CreateBucketConfiguration xmlns="#{xmlns}"> <LocationConstraint>#{location}</LocationConstraint> </CreateBucketConfiguration> XML end super(req, ) end end |
#delete_bucket(options = {}) ⇒ Core::Response
Deletes an empty bucket.
159 |
# File 'lib/aws/s3/client.rb', line 159 bucket_method(:delete_bucket, :delete) |
#delete_bucket_cors(options = {}) ⇒ Core::Response
303 304 305 306 307 308 |
# File 'lib/aws/s3/client.rb', line 303 bucket_method(:delete_bucket_cors, :delete) do configure_request do |req, | req.add_param('cors') super(req, ) end end |
#delete_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response
200 201 202 203 204 205 206 207 |
# File 'lib/aws/s3/client.rb', line 200 bucket_method(:delete_bucket_lifecycle_configuration, :delete) do configure_request do |req, | req.add_param('lifecycle') super(req, ) end end |
#delete_bucket_policy(options = {}) ⇒ Core::Response
Deletes the access policy for a bucket.
425 |
# File 'lib/aws/s3/client.rb', line 425 bucket_method(:delete_bucket_policy, :delete, 'policy') |
#delete_bucket_tagging(options = {}) ⇒ Core::Response
362 363 364 365 366 367 |
# File 'lib/aws/s3/client.rb', line 362 bucket_method(:delete_bucket_tagging, :delete) do configure_request do |req, | req.add_param('tagging') super(req, ) end end |
#delete_object(options = {}) ⇒ Core::Response
958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
# File 'lib/aws/s3/client.rb', line 958 object_method(:delete_object, :delete, :header_options => { :mfa => "x-amz-mfa" }) do configure_request do |req, | super(req, ) if [:version_id] req.add_param('versionId', [:version_id]) end end process_response do |resp| resp.data[:version_id] = resp.http_response.header('x-amz-version-id') end end |
#delete_objects(options = {}) ⇒ Core::Response
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/aws/s3/client.rb', line 1083 bucket_method(:delete_objects, :post, 'delete', XML::DeleteObjects, :header_options => { :mfa => "x-amz-mfa" }) do configure_request do |req, | super(req, ) quiet = .key?(:quiet) ? [:quiet] : true # previously named this option :objects, since renamed keys = [:objects] || [:keys] objects = keys.inject('') do |xml,o| xml << "<Object><Key>#{REXML::Text.normalize(o[:key])}</Key>" xml << "<VersionId>#{o[:version_id]}</VersionId>" if o[:version_id] xml << "</Object>" end xml = '<?xml version="1.0" encoding="UTF-8"?>' xml << "<Delete><Quiet>#{quiet}</Quiet>#{objects}</Delete>" req.body = xml req.headers['content-md5'] = md5(xml) end end |
#get_bucket_acl(options = {}) ⇒ Core::Response
Gets the access control list for a bucket.
591 |
# File 'lib/aws/s3/client.rb', line 591 bucket_method(:get_bucket_acl, :get, 'acl', XML::GetBucketAcl) |
#get_bucket_cors(options = {}) ⇒ Core::Response
286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/aws/s3/client.rb', line 286 bucket_method(:get_bucket_cors, :get) do configure_request do |req, | req.add_param('cors') super(req, ) end process_response do |resp| resp.data = XML::GetBucketCors.parse(resp.http_response.body) end end |
#get_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/aws/s3/client.rb', line 182 bucket_method(:get_bucket_lifecycle_configuration, :get) do configure_request do |req, | req.add_param('lifecycle') super(req, ) end process_response do |resp| xml = resp.http_response.body resp.data = XML::GetBucketLifecycleConfiguration.parse(xml) end end |
#get_bucket_location(options = {}) ⇒ Core::Response
Gets the bucket’s location constraint.
463 464 465 466 467 468 469 470 471 |
# File 'lib/aws/s3/client.rb', line 463 bucket_method(:get_bucket_location, :get, 'location') do process_response do |response| regex = />(.*)<\/LocationConstraint>/ matches = response.http_response.body.to_s.match(regex) response.data[:location_constraint] = matches ? matches[1] : nil end end |
#get_bucket_policy(options = {}) ⇒ Core::Response
Gets the access policy for a bucket.
412 413 414 415 416 417 418 |
# File 'lib/aws/s3/client.rb', line 412 bucket_method(:get_bucket_policy, :get, 'policy') do process_response do |resp| resp.data[:policy] = resp.http_response.body end end |
#get_bucket_tagging(options = {}) ⇒ Core::Response
345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/aws/s3/client.rb', line 345 bucket_method(:get_bucket_tagging, :get) do configure_request do |req, | req.add_param('tagging') super(req, ) end process_response do |resp| resp.data = XML::GetBucketTagging.parse(resp.http_response.body) end end |
#get_bucket_versioning(options = {}) ⇒ Core::Response
477 478 |
# File 'lib/aws/s3/client.rb', line 477 bucket_method(:get_bucket_versioning, :get, 'versioning', XML::GetBucketVersioning) |
#get_object(options = {}) ⇒ Core::Response
Gets the data for a key.
852 853 854 855 856 857 858 859 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 |
# File 'lib/aws/s3/client.rb', line 852 object_method(:get_object, :get, :header_options => { :if_modified_since => "If-Modified-Since", :if_unmodified_since => "If-Unmodified-Since", :if_match => "If-Match", :if_none_match => "If-None-Match" }) do configure_request do |req, | super(req, ) if [:version_id] req.add_param('versionId', [:version_id]) end ["If-Modified-Since", "If-Unmodified-Since"].each do |date_header| case value = req.headers[date_header] when DateTime req.headers[date_header] = Time.parse(value.to_s).rfc2822 when Time req.headers[date_header] = value.rfc2822 end end if [:range] range = [:range] range = "bytes=#{range.first}-#{range.last}" if range.is_a?(Range) req.headers['Range'] = range end end process_response do |resp| resp.data[:data] = resp.http_response.body resp.data[:version_id] = resp.http_response.header('x-amz-version-id') add_sse_to_response(resp) end end |
#get_object_acl(options = {}) ⇒ Core::Response
Gets the access control list for an object.
685 |
# File 'lib/aws/s3/client.rb', line 685 object_method(:get_object_acl, :get, 'acl', XML::GetBucketAcl) |
#head_object(options = {}) ⇒ Core::Response
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 |
# File 'lib/aws/s3/client.rb', line 898 object_method(:head_object, :head) do configure_request do |req, | super(req, ) if [:version_id] req.add_param('versionId', [:version_id]) end end process_response do |resp| # create a hash of user-supplied metadata = {} resp.http_response.headers.each_pair do |name,value| if name =~ /^x-amz-meta-(.+)$/i [$1] = [value].flatten.join end end resp.data[:meta] = if expiry = resp.http_response.headers['x-amz-expiration'] expiry.first =~ /^expiry-date="(.+)", rule-id="(.+)"$/ exp_date = DateTime.parse($1) exp_rule_id = $2 else exp_date = nil exp_rule_id = nil end resp.data[:expiration_date] = exp_date resp.data[:expiration_rule_id] = exp_rule_id { 'x-amz-version-id' => :version_id, 'content-type' => :content_type, 'etag' => :etag, }.each_pair do |header,method| resp.data[method] = resp.http_response.header(header) end if time = resp.http_response.header('Last-Modified') resp.data[:last_modified] = Time.parse(time) end resp.data[:content_length] = resp.http_response.header('content-length').to_i add_sse_to_response(resp) end end |
#initiate_multipart_upload(options = {}) ⇒ Core::Response
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
# File 'lib/aws/s3/client.rb', line 1022 object_method(:initiate_multipart_upload, :post, 'uploads', XML::InitiateMultipartUpload, :header_options => { :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', :cache_control => 'Cache-Control', :content_disposition => 'Content-Disposition', :content_encoding => 'Content-Encoding', :content_type => 'Content-Type', :expires => 'Expires' }) do configure_request do |req, | req. = [:metadata] req.storage_class = [:storage_class] req.server_side_encryption = [:server_side_encryption] super(req, ) end process_response do |response| add_sse_to_response(response) end end |
#list_buckets(options = {}) ⇒ Core::Response
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/aws/s3/client.rb', line 372 add_client_request_method(:list_buckets) do configure_request do |req, | req.http_method = "GET" end process_response do |resp| resp.data = XML::ListBuckets.parse(resp.http_response.body) end simulate_response do |resp| resp.data = Core::XML::Parser.new(XML::ListBuckets.rules).simulate end end |
#list_multipart_uploads(options = {}) ⇒ Core::Response
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 |
# File 'lib/aws/s3/client.rb', line 1061 bucket_method(:list_multipart_uploads, :get, 'uploads', XML::ListMultipartUploads) do configure_request do |req, | super(req, ) params = %w(delimiter key_marker max_keys) + %w(upload_id_marker max_uploads prefix) params.each do |param| if [param.to_sym] req.add_param(param.gsub(/_/, '-'), [param.to_sym]) end end end end |
#list_object_versions(options = {}) ⇒ Core::Response
489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/aws/s3/client.rb', line 489 bucket_method(:list_object_versions, :get, 'versions', XML::ListObjectVersions) do configure_request do |req, | super(req, ) params = %w(delimiter key_marker max_keys prefix version_id_marker) params.each do |param| if [param.to_sym] req.add_param(param.gsub(/_/, '-'), [param.to_sym]) end end end end |
#list_objects(options = {}) ⇒ Core::Response Also known as: get_bucket
981 982 983 984 985 986 987 988 989 990 991 |
# File 'lib/aws/s3/client.rb', line 981 bucket_method(:list_objects, :get, XML::ListObjects) do configure_request do |req, | super(req, ) params = %w(delimiter marker max_keys prefix) params.each do |param| if [param.to_sym] req.add_param(param.gsub(/_/, '-'), [param.to_sym]) end end end end |
#list_parts(options = {}) ⇒ Core::Response
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 |
# File 'lib/aws/s3/client.rb', line 1208 object_method(:list_parts, :get, XML::ListParts) do configure_request do |req, | require_upload_id!([:upload_id]) super(req, ) req.add_param('uploadId', [:upload_id]) req.add_param('max-parts', [:max_parts]) req.add_param('part-number-marker', [:part_number_marker]) end end |
#put_bucket_acl(options = {}) ⇒ Core::Response Also known as: set_bucket_acl
Sets the access control list for a bucket. You must specify an ACL via one of the following methods:
-
as a canned ACL (via
:acl
) -
as a list of grants (via the
:grant_*
options) -
as an access control policy document (via
:access_control_policy
)
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
# File 'lib/aws/s3/client.rb', line 566 bucket_method(:put_bucket_acl, :put, 'acl', :header_options => { :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', }) do configure_request do |req, | move_access_control_policy() require_acl!() super(req, ) req.body = [:access_control_policy] if [:access_control_policy] end end |
#put_bucket_cors(options = {}) ⇒ Core::Response
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/aws/s3/client.rb', line 238 bucket_method(:put_bucket_cors, :put) do configure_request do |req, | req.add_param('cors') xml = Nokogiri::XML::Builder.new do |xml| xml.CORSConfiguration do [:rules].each do |rule| xml.CORSRule do xml.ID(rule[:id]) if rule[:id] (rule[:allowed_methods] || []).each do |method| xml.AllowedMethod(method) end (rule[:allowed_origins] || []).each do |origin| xml.AllowedOrigin(origin) end (rule[:allowed_headers] || []).each do |header| xml.AllowedHeader(header) end xml.MaxAgeSeconds(rule[:max_age_seconds]) if rule[:max_age_seconds] (rule[:expose_headers] || []).each do |header| xml.ExposeHeader(header) end end end end end.doc.root.to_xml req.body = xml req.headers['content-md5'] = md5(xml) super(req, ) end end |
#put_bucket_tagging(options = {}) ⇒ Core::Response
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/aws/s3/client.rb', line 315 bucket_method(:put_bucket_tagging, :put) do configure_request do |req, | req.add_param('tagging') xml = Nokogiri::XML::Builder.new xml.Tagging do |xml| xml.TagSet do [:tags].each_pair do |key,value| xml.Tag do xml.Key(key) xml.Value(value) end end end end xml = xml.doc.root.to_xml req.body = xml req.headers['content-md5'] = md5(xml) super(req, ) end end |
#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.
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 |
# File 'lib/aws/s3/client.rb', line 774 object_method(:put_object, :put, :header_options => { :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 |response| response.data[:version_id] = response.http_response.header('x-amz-version-id') response.data[:etag] = response.http_response.header('ETag') if time = response.http_response.header('Last-Modified') response.data[:last_modified] = Time.parse(time) end add_sse_to_response(response) end simulate_response do |response| response.data[:etag] = 'abc123' response.data[:version_id] = nil end end |
#put_object_acl(options = {}) ⇒ Core::Response Also known as: set_object_acl
Sets the access control list for an object. You must specify an ACL via one of the following methods:
-
as a canned ACL (via
:acl
) -
as a list of grants (via the
:grant_*
options) -
as an access control policy document (via
:access_control_policy
)
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
# File 'lib/aws/s3/client.rb', line 659 object_method(:put_object_acl, :put, 'acl', :header_options => { :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', }) do configure_request do |req, | move_access_control_policy() require_acl!() super(req, ) req.body = [:access_control_policy] if [:access_control_policy] end end |
#set_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/aws/s3/client.rb', line 166 bucket_method(:set_bucket_lifecycle_configuration, :put) do configure_request do |req, | xml = [:lifecycle_configuration] req.add_param('lifecycle') req.body = xml req.headers['content-md5'] = md5(xml) super(req, ) end end |
#set_bucket_policy(options = {}) ⇒ Core::Response
Sets the access policy for a bucket.
395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/aws/s3/client.rb', line 395 bucket_method(:set_bucket_policy, :put, 'policy') do configure_request do |req, | require_policy!([:policy]) super(req, ) policy = [:policy] policy = policy.to_json unless policy.respond_to?(:to_str) req.body = policy end end |
#set_bucket_versioning(options = {}) ⇒ Core::Response
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/aws/s3/client.rb', line 434 bucket_method(:set_bucket_versioning, :put, 'versioning', :header_options => { :mfa => "x-amz-mfa" }) do configure_request do |req, | state = [:state].to_s.downcase.capitalize unless state =~ /^(Enabled|Suspended)$/ raise ArgumentError, "invalid versioning state `#{state}`" end # Leave validation of MFA options to S3 mfa_delete = [:mfa_delete].to_s.downcase.capitalize if [:mfa_delete] # Generate XML request for versioning req.body = Nokogiri::XML::Builder.new do |xml| xml.VersioningConfiguration('xmlns' => XMLNS) do xml.Status(state) xml.MfaDelete(mfa_delete) if mfa_delete end end.doc.root.to_xml super(req, ) end end |
#upload_part(options = {}) ⇒ Core::Response
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 |
# File 'lib/aws/s3/client.rb', line 1119 object_method(:upload_part, :put, :header_options => { :content_md5 => 'Content-MD5' }) do configure_request do |request, | = () set_body_stream_and_content_length(request, ) require_upload_id!([:upload_id]) request.add_param('uploadId', [:upload_id]) require_part_number!([:part_number]) request.add_param('partNumber', [:part_number]) super(request, ) end process_response do |response| response.data[:etag] = response.http_response.header('ETag') if time = response.http_response.header('Last-Modified') response.data[:last_modified] = Time.parse(time) end add_sse_to_response(response) end simulate_response do |response| response.data[:etag] = 'abc123' end end |