1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package s3
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
10	s3cust "github.com/aws/aws-sdk-go-v2/service/s3/internal/customizations"
11	"github.com/aws/aws-sdk-go-v2/service/s3/types"
12	"github.com/aws/smithy-go/middleware"
13	smithyhttp "github.com/aws/smithy-go/transport/http"
14	"io"
15	"time"
16)
17
18// Adds an object to a bucket. You must have WRITE permissions on a bucket to add
19// an object to it. Amazon S3 never adds partial objects; if you receive a success
20// response, Amazon S3 added the entire object to the bucket. Amazon S3 is a
21// distributed system. If it receives multiple write requests for the same object
22// simultaneously, it overwrites all but the last object written. Amazon S3 does
23// not provide object locking; if you need this, make sure to build it into your
24// application layer or use versioning instead. To ensure that data is not
25// corrupted traversing the network, use the Content-MD5 header. When you use this
26// header, Amazon S3 checks the object against the provided MD5 value and, if they
27// do not match, returns an error. Additionally, you can calculate the MD5 while
28// putting an object to Amazon S3 and compare the returned ETag to the calculated
29// MD5 value. The Content-MD5 header is required for any request to upload an
30// object with a retention period configured using Amazon S3 Object Lock. For more
31// information about Amazon S3 Object Lock, see Amazon S3 Object Lock Overview
32// (https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock-overview.html) in
33// the Amazon S3 User Guide. Server-side Encryption You can optionally request
34// server-side encryption. With server-side encryption, Amazon S3 encrypts your
35// data as it writes it to disks in its data centers and decrypts the data when you
36// access it. You have the option to provide your own encryption key or use AWS
37// managed encryption keys (SSE-S3 or SSE-KMS). For more information, see Using
38// Server-Side Encryption
39// (https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html).
40// If you request server-side encryption using AWS Key Management Service
41// (SSE-KMS), you can enable an S3 Bucket Key at the object-level. For more
42// information, see Amazon S3 Bucket Keys
43// (https://docs.aws.amazon.com/AmazonS3/latest/dev/bucket-key.html) in the Amazon
44// S3 User Guide. Access Control List (ACL)-Specific Request Headers You can use
45// headers to grant ACL- based permissions. By default, all objects are private.
46// Only the owner has full access control. When adding a new object, you can grant
47// permissions to individual AWS accounts or to predefined groups defined by Amazon
48// S3. These permissions are then added to the ACL on the object. For more
49// information, see Access Control List (ACL) Overview
50// (https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html) and Managing
51// ACLs Using the REST API
52// (https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-using-rest-api.html).
53// Storage Class Options By default, Amazon S3 uses the STANDARD Storage Class to
54// store newly created objects. The STANDARD storage class provides high durability
55// and high availability. Depending on performance needs, you can specify a
56// different Storage Class. Amazon S3 on Outposts only uses the OUTPOSTS Storage
57// Class. For more information, see Storage Classes
58// (https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html) in
59// the Amazon S3 Service Developer Guide. Versioning If you enable versioning for a
60// bucket, Amazon S3 automatically generates a unique version ID for the object
61// being stored. Amazon S3 returns this ID in the response. When you enable
62// versioning for a bucket, if Amazon S3 receives multiple write requests for the
63// same object simultaneously, it stores all of the objects. For more information
64// about versioning, see Adding Objects to Versioning Enabled Buckets
65// (https://docs.aws.amazon.com/AmazonS3/latest/dev/AddingObjectstoVersioningEnabledBuckets.html).
66// For information about returning the versioning state of a bucket, see
67// GetBucketVersioning
68// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketVersioning.html).
69// Related Resources
70//
71// * CopyObject
72// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html)
73//
74// *
75// DeleteObject
76// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html)
77func (c *Client) PutObject(ctx context.Context, params *PutObjectInput, optFns ...func(*Options)) (*PutObjectOutput, error) {
78	if params == nil {
79		params = &PutObjectInput{}
80	}
81
82	result, metadata, err := c.invokeOperation(ctx, "PutObject", params, optFns, addOperationPutObjectMiddlewares)
83	if err != nil {
84		return nil, err
85	}
86
87	out := result.(*PutObjectOutput)
88	out.ResultMetadata = metadata
89	return out, nil
90}
91
92type PutObjectInput struct {
93
94	// The bucket name to which the PUT action was initiated. When using this action
95	// with an access point, you must direct requests to the access point hostname. The
96	// access point hostname takes the form
97	// AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this
98	// action with an access point through the AWS SDKs, you provide the access point
99	// ARN in place of the bucket name. For more information about access point ARNs,
100	// see Using Access Points
101	// (https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html)
102	// in the Amazon S3 User Guide. When using this action with Amazon S3 on Outposts,
103	// you must direct requests to the S3 on Outposts hostname. The S3 on Outposts
104	// hostname takes the form
105	// AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using
106	// this action using S3 on Outposts through the AWS SDKs, you provide the Outposts
107	// bucket ARN in place of the bucket name. For more information about S3 on
108	// Outposts ARNs, see Using S3 on Outposts
109	// (https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3onOutposts.html) in the
110	// Amazon S3 User Guide.
111	//
112	// This member is required.
113	Bucket *string
114
115	// Object key for which the PUT action was initiated.
116	//
117	// This member is required.
118	Key *string
119
120	// The canned ACL to apply to the object. For more information, see Canned ACL
121	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#CannedACL).
122	// This action is not supported by Amazon S3 on Outposts.
123	ACL types.ObjectCannedACL
124
125	// Object data.
126	//
127	// For using values that are not seekable (io.Seeker) see,
128	// https://aws.github.io/aws-sdk-go-v2/docs/sdk-utilisties/s3/#unseekable-streaming-input
129	Body io.Reader
130
131	// Specifies whether Amazon S3 should use an S3 Bucket Key for object encryption
132	// with server-side encryption using AWS KMS (SSE-KMS). Setting this header to true
133	// causes Amazon S3 to use an S3 Bucket Key for object encryption with SSE-KMS.
134	// Specifying this header with a PUT action doesn’t affect bucket-level settings
135	// for S3 Bucket Key.
136	BucketKeyEnabled bool
137
138	// Can be used to specify caching behavior along the request/reply chain. For more
139	// information, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
140	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9).
141	CacheControl *string
142
143	// Specifies presentational information for the object. For more information, see
144	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1
145	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1).
146	ContentDisposition *string
147
148	// Specifies what content encodings have been applied to the object and thus what
149	// decoding mechanisms must be applied to obtain the media-type referenced by the
150	// Content-Type header field. For more information, see
151	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
152	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11).
153	ContentEncoding *string
154
155	// The language the content is in.
156	ContentLanguage *string
157
158	// Size of the body in bytes. This parameter is useful when the size of the body
159	// cannot be determined automatically. For more information, see
160	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
161	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13).
162	ContentLength int64
163
164	// The base64-encoded 128-bit MD5 digest of the message (without the headers)
165	// according to RFC 1864. This header can be used as a message integrity check to
166	// verify that the data is the same data that was originally sent. Although it is
167	// optional, we recommend using the Content-MD5 mechanism as an end-to-end
168	// integrity check. For more information about REST request authentication, see
169	// REST Authentication
170	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html).
171	ContentMD5 *string
172
173	// A standard MIME type describing the format of the contents. For more
174	// information, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17
175	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17).
176	ContentType *string
177
178	// The account ID of the expected bucket owner. If the bucket is owned by a
179	// different account, the request will fail with an HTTP 403 (Access Denied) error.
180	ExpectedBucketOwner *string
181
182	// The date and time at which the object is no longer cacheable. For more
183	// information, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21
184	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21).
185	Expires *time.Time
186
187	// Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. This
188	// action is not supported by Amazon S3 on Outposts.
189	GrantFullControl *string
190
191	// Allows grantee to read the object data and its metadata. This action is not
192	// supported by Amazon S3 on Outposts.
193	GrantRead *string
194
195	// Allows grantee to read the object ACL. This action is not supported by Amazon S3
196	// on Outposts.
197	GrantReadACP *string
198
199	// Allows grantee to write the ACL for the applicable object. This action is not
200	// supported by Amazon S3 on Outposts.
201	GrantWriteACP *string
202
203	// A map of metadata to store with the object in S3.
204	Metadata map[string]string
205
206	// Specifies whether a legal hold will be applied to this object. For more
207	// information about S3 Object Lock, see Object Lock
208	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock.html).
209	ObjectLockLegalHoldStatus types.ObjectLockLegalHoldStatus
210
211	// The Object Lock mode that you want to apply to this object.
212	ObjectLockMode types.ObjectLockMode
213
214	// The date and time when you want this object's Object Lock to expire.
215	ObjectLockRetainUntilDate *time.Time
216
217	// Confirms that the requester knows that they will be charged for the request.
218	// Bucket owners need not specify this parameter in their requests. For information
219	// about downloading objects from requester pays buckets, see Downloading Objects
220	// in Requestor Pays Buckets
221	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html)
222	// in the Amazon S3 Developer Guide.
223	RequestPayer types.RequestPayer
224
225	// Specifies the algorithm to use to when encrypting the object (for example,
226	// AES256).
227	SSECustomerAlgorithm *string
228
229	// Specifies the customer-provided encryption key for Amazon S3 to use in
230	// encrypting data. This value is used to store the object and then it is
231	// discarded; Amazon S3 does not store the encryption key. The key must be
232	// appropriate for use with the algorithm specified in the
233	// x-amz-server-side-encryption-customer-algorithm header.
234	SSECustomerKey *string
235
236	// Specifies the 128-bit MD5 digest of the encryption key according to RFC 1321.
237	// Amazon S3 uses this header for a message integrity check to ensure that the
238	// encryption key was transmitted without error.
239	SSECustomerKeyMD5 *string
240
241	// Specifies the AWS KMS Encryption Context to use for object encryption. The value
242	// of this header is a base64-encoded UTF-8 string holding JSON with the encryption
243	// context key-value pairs.
244	SSEKMSEncryptionContext *string
245
246	// If x-amz-server-side-encryption is present and has the value of aws:kms, this
247	// header specifies the ID of the AWS Key Management Service (AWS KMS) symmetrical
248	// customer managed customer master key (CMK) that was used for the object. If the
249	// value of x-amz-server-side-encryption is aws:kms, this header specifies the ID
250	// of the symmetric customer managed AWS KMS CMK that will be used for the object.
251	// If you specify x-amz-server-side-encryption:aws:kms, but do not provide
252	// x-amz-server-side-encryption-aws-kms-key-id, Amazon S3 uses the AWS managed CMK
253	// in AWS to protect the data.
254	SSEKMSKeyId *string
255
256	// The server-side encryption algorithm used when storing this object in Amazon S3
257	// (for example, AES256, aws:kms).
258	ServerSideEncryption types.ServerSideEncryption
259
260	// By default, Amazon S3 uses the STANDARD Storage Class to store newly created
261	// objects. The STANDARD storage class provides high durability and high
262	// availability. Depending on performance needs, you can specify a different
263	// Storage Class. Amazon S3 on Outposts only uses the OUTPOSTS Storage Class. For
264	// more information, see Storage Classes
265	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html) in
266	// the Amazon S3 Service Developer Guide.
267	StorageClass types.StorageClass
268
269	// The tag-set for the object. The tag-set must be encoded as URL Query parameters.
270	// (For example, "Key1=Value1")
271	Tagging *string
272
273	// If the bucket is configured as a website, redirects requests for this object to
274	// another object in the same bucket or to an external URL. Amazon S3 stores the
275	// value of this header in the object metadata. For information about object
276	// metadata, see Object Key and Metadata
277	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html). In the
278	// following example, the request header sets the redirect to an object
279	// (anotherPage.html) in the same bucket: x-amz-website-redirect-location:
280	// /anotherPage.html In the following example, the request header sets the object
281	// redirect to another website: x-amz-website-redirect-location:
282	// http://www.example.com/ For more information about website hosting in Amazon S3,
283	// see Hosting Websites on Amazon S3
284	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html) and How to
285	// Configure Website Page Redirects
286	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html).
287	WebsiteRedirectLocation *string
288}
289
290type PutObjectOutput struct {
291
292	// Indicates whether the uploaded object uses an S3 Bucket Key for server-side
293	// encryption with AWS KMS (SSE-KMS).
294	BucketKeyEnabled bool
295
296	// Entity tag for the uploaded object.
297	ETag *string
298
299	// If the expiration is configured for the object (see
300	// PutBucketLifecycleConfiguration
301	// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketLifecycleConfiguration.html)),
302	// the response includes this header. It includes the expiry-date and rule-id
303	// key-value pairs that provide information about object expiration. The value of
304	// the rule-id is URL encoded.
305	Expiration *string
306
307	// If present, indicates that the requester was successfully charged for the
308	// request.
309	RequestCharged types.RequestCharged
310
311	// If server-side encryption with a customer-provided encryption key was requested,
312	// the response will include this header confirming the encryption algorithm used.
313	SSECustomerAlgorithm *string
314
315	// If server-side encryption with a customer-provided encryption key was requested,
316	// the response will include this header to provide round-trip message integrity
317	// verification of the customer-provided encryption key.
318	SSECustomerKeyMD5 *string
319
320	// If present, specifies the AWS KMS Encryption Context to use for object
321	// encryption. The value of this header is a base64-encoded UTF-8 string holding
322	// JSON with the encryption context key-value pairs.
323	SSEKMSEncryptionContext *string
324
325	// If x-amz-server-side-encryption is present and has the value of aws:kms, this
326	// header specifies the ID of the AWS Key Management Service (AWS KMS) symmetric
327	// customer managed customer master key (CMK) that was used for the object.
328	SSEKMSKeyId *string
329
330	// If you specified server-side encryption either with an AWS KMS customer master
331	// key (CMK) or Amazon S3-managed encryption key in your PUT request, the response
332	// includes this header. It confirms the encryption algorithm that Amazon S3 used
333	// to encrypt the object.
334	ServerSideEncryption types.ServerSideEncryption
335
336	// Version of the object.
337	VersionId *string
338
339	// Metadata pertaining to the operation's result.
340	ResultMetadata middleware.Metadata
341}
342
343func addOperationPutObjectMiddlewares(stack *middleware.Stack, options Options) (err error) {
344	err = stack.Serialize.Add(&awsRestxml_serializeOpPutObject{}, middleware.After)
345	if err != nil {
346		return err
347	}
348	err = stack.Deserialize.Add(&awsRestxml_deserializeOpPutObject{}, middleware.After)
349	if err != nil {
350		return err
351	}
352	if err = addSetLoggerMiddleware(stack, options); err != nil {
353		return err
354	}
355	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
356		return err
357	}
358	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
359		return err
360	}
361	if err = addResolveEndpointMiddleware(stack, options); err != nil {
362		return err
363	}
364	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
365		return err
366	}
367	if err = addRetryMiddlewares(stack, options); err != nil {
368		return err
369	}
370	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
371		return err
372	}
373	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
374		return err
375	}
376	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
377		return err
378	}
379	if err = addClientUserAgent(stack); err != nil {
380		return err
381	}
382	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
383		return err
384	}
385	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
386		return err
387	}
388	if err = addOpPutObjectValidationMiddleware(stack); err != nil {
389		return err
390	}
391	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutObject(options.Region), middleware.Before); err != nil {
392		return err
393	}
394	if err = addMetadataRetrieverMiddleware(stack); err != nil {
395		return err
396	}
397	if err = addPutObjectUpdateEndpoint(stack, options); err != nil {
398		return err
399	}
400	if err = addResponseErrorMiddleware(stack); err != nil {
401		return err
402	}
403	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
404		return err
405	}
406	if err = disableAcceptEncodingGzip(stack); err != nil {
407		return err
408	}
409	if err = addRequestResponseLogging(stack, options); err != nil {
410		return err
411	}
412	return nil
413}
414
415func newServiceMetadataMiddleware_opPutObject(region string) *awsmiddleware.RegisterServiceMetadata {
416	return &awsmiddleware.RegisterServiceMetadata{
417		Region:        region,
418		ServiceID:     ServiceID,
419		SigningName:   "s3",
420		OperationName: "PutObject",
421	}
422}
423
424// getPutObjectBucketMember returns a pointer to string denoting a provided bucket
425// member valueand a boolean indicating if the input has a modeled bucket name,
426func getPutObjectBucketMember(input interface{}) (*string, bool) {
427	in := input.(*PutObjectInput)
428	if in.Bucket == nil {
429		return nil, false
430	}
431	return in.Bucket, true
432}
433func addPutObjectUpdateEndpoint(stack *middleware.Stack, options Options) error {
434	return s3cust.UpdateEndpoint(stack, s3cust.UpdateEndpointOptions{
435		Accessor: s3cust.UpdateEndpointParameterAccessor{
436			GetBucketFromInput: getPutObjectBucketMember,
437		},
438		UsePathStyle:            options.UsePathStyle,
439		UseAccelerate:           options.UseAccelerate,
440		SupportsAccelerate:      true,
441		TargetS3ObjectLambda:    false,
442		EndpointResolver:        options.EndpointResolver,
443		EndpointResolverOptions: options.EndpointOptions,
444		UseDualstack:            options.UseDualstack,
445		UseARNRegion:            options.UseARNRegion,
446	})
447}
448
449// PresignPutObject is used to generate a presigned HTTP Request which contains
450// presigned URL, signed headers and HTTP method used.
451func (c *PresignClient) PresignPutObject(ctx context.Context, params *PutObjectInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error) {
452	if params == nil {
453		params = &PutObjectInput{}
454	}
455	options := c.options.copy()
456	for _, fn := range optFns {
457		fn(&options)
458	}
459	clientOptFns := append(options.ClientOptions, withNopHTTPClientAPIOption)
460
461	result, _, err := c.client.invokeOperation(ctx, "PutObject", params, clientOptFns,
462		addOperationPutObjectMiddlewares,
463		presignConverter(options).convertToPresignMiddleware,
464		func(stack *middleware.Stack, options Options) error {
465			return awshttp.RemoveContentTypeHeader(stack)
466		},
467		addPutObjectPayloadAsUnsigned,
468	)
469	if err != nil {
470		return nil, err
471	}
472
473	out := result.(*v4.PresignedHTTPRequest)
474	return out, nil
475}
476
477func addPutObjectPayloadAsUnsigned(stack *middleware.Stack, options Options) error {
478	v4.RemoveContentSHA256HeaderMiddleware(stack)
479	v4.RemoveComputePayloadSHA256Middleware(stack)
480	return v4.AddUnsignedPayloadMiddleware(stack)
481}
482