Method: Aws::S3::Client#put_object
- Defined in:
- lib/aws-sdk-s3/client.rb
#put_object(params = {}) ⇒ Types::PutObjectOutput
Adds an object to a bucket. You must have WRITE permissions on a bucket to add an object to it.
Amazon S3 never adds partial objects; if you receive a success response, Amazon S3 added the entire object to the bucket.
Amazon S3 is a distributed system. If it receives multiple write requests for the same object simultaneously, it overwrites all but the last object written. Amazon S3 does not provide object locking; if you need this, make sure to build it into your application layer or use versioning instead.
To ensure that data is not corrupted traversing the network, use the ‘Content-MD5` header. When you use this header, Amazon S3 checks the object against the provided MD5 value and, if they do not match, returns an error. Additionally, you can calculate the MD5 while putting an object to Amazon S3 and compare the returned ETag to the calculated MD5 value.
<note markdown=“1”> To configure your application to send the request headers before sending the request body, use the ‘100-continue` HTTP status code. For PUT operations, this helps you avoid sending the message body if the message is rejected based on the headers (for example, because authentication fails or a redirect occurs). For more information on the `100-continue` HTTP status code, see Section 8.2.3 of [www.ietf.org/rfc/rfc2616.txt][1].
</note>
You can optionally request server-side encryption. With server-side encryption, Amazon S3 encrypts your data as it writes it to disks in its data centers and decrypts the data when you access it. You have the option to provide your own encryption key or use AWS managed encryption keys. For more information, see [Using Server-Side Encryption].
Access Permissions
: You can optionally specify the accounts or groups that should be
granted specific on the new object. There are two ways
to grant the using the request headers:
* Specify a canned ACL with the `x-amz-acl` request header. For more
information, see [Canned ACL][3].
* Specify access explicitly with the `x-amz-grant-read`,
`x-amz-grant-read-acp`, `x-amz-grant-write-acp`, and
`x-amz-grant-full-control` headers. These parameters map to the
set of that Amazon S3 supports in an ACL. For more
information, see [Access Control List (ACL) Overview][4].
You can use either a canned ACL or specify access
explicitly. You cannot do both.
Server-Side- Encryption-Specific Request Headers
: You can optionally tell Amazon S3 to encrypt data at rest using
server-side encryption. Server-side encryption is for data
encryption at rest. Amazon S3 encrypts your data as it writes it to
disks in its data centers and decrypts it when you access it. The
option you use depends on whether you want to use AWS managed
encryption keys or provide your own encryption key.
* Use encryption keys managed by Amazon S3 or customer master keys
(CMKs) stored in AWS Key Management Service (AWS KMS)
Access-Control-List (ACL)-Specific Request Headers
: You also can use the following access control–related headers with
this operation. By default, all objects are private. Only the owner
has full access control. When adding a new object, you can grant
to individual AWS accounts or to predefined groups
defined by Amazon S3. These are then added to the Access
Control List (ACL) on the object. For more information, see [Using
ACLs][7]. With this operation, you can grant access
using one of the following two methods:
* Specify a canned ACL (`x-amz-acl`)
Server-Side- Encryption-Specific Request Headers
: You can optionally tell Amazon S3 to encrypt data at rest using
server-side encryption. Server-side encryption is for data
encryption at rest. Amazon S3 encrypts your data as it writes it to
disks in its data centers and decrypts it when you access it. The
option you use depends on whether you want to use AWS-managed
encryption keys or provide your own encryption key.
* Use encryption keys managed by Amazon S3 or customer master keys
(CMKs) stored in AWS Key Management Service (AWS KMS)
**Storage Class Options**
By default, Amazon S3 uses the Standard storage class to store newly created objects. The Standard storage class provides high durability and high availability. You can specify other storage classes depending on the performance needs. For more information, see [Storage Classes] in the Amazon Simple Storage Service Developer Guide.
Versioning
If you enable versioning for a bucket, Amazon S3 automatically generates a unique version ID for the object being stored. Amazon S3 returns this ID in the response using the ‘x-amz-version-id response` header. If versioning is suspended, Amazon S3 always uses null as the version ID for the object stored. For more information about returning the versioning state of a bucket, see GetBucketVersioning. If you enable versioning for a bucket, when Amazon S3 receives multiple write requests for the same object simultaneously, it stores all of the objects.
**Related Resources**
-
CopyObject
-
DeleteObject
[1]: www.ietf.org/rfc/rfc2616.txt [2]: docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html [3]: docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#CannedACL [4]: docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html [5]: docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html [6]: docs.aws.amazon.com/AmazonS3/latest/dev/UsingKMSEncryption.html [7]: docs.aws.amazon.com/AmazonS3/latest/dev/S3_ACLs_UsingACLs.html [8]: docs.aws.amazon.com/general/latest/gr/rande.html#s3_region [9]: docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html
9740 9741 9742 9743 |
# File 'lib/aws-sdk-s3/client.rb', line 9740 def put_object(params = {}, = {}) req = build_request(:put_object, params) req.send_request() end |