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)
16
17// Uploads a part in a multipart upload. In this operation, you provide part data
18// in your request. However, you have an option to specify your existing Amazon S3
19// object as a data source for the part you are uploading. To upload a part from an
20// existing object, you use the UploadPartCopy
21// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html)
22// operation. You must initiate a multipart upload (see CreateMultipartUpload
23// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html))
24// before you can upload any part. In response to your initiate request, Amazon S3
25// returns an upload ID, a unique identifier, that you must include in your upload
26// part request. Part numbers can be any number from 1 to 10,000, inclusive. A part
27// number uniquely identifies a part and also defines its position within the
28// object being created. If you upload a new part using the same part number that
29// was used with a previous part, the previously uploaded part is overwritten. Each
30// part must be at least 5 MB in size, except the last part. There is no size limit
31// on the last part of your multipart upload. To ensure that data is not corrupted
32// when traversing the network, specify the Content-MD5 header in the upload part
33// request. Amazon S3 checks the part data against the provided MD5 value. If they
34// do not match, Amazon S3 returns an error. If the upload request is signed with
35// Signature Version 4, then Amazon Web Services S3 uses the x-amz-content-sha256
36// header as a checksum instead of Content-MD5. For more information see
37// Authenticating Requests: Using the Authorization Header (Amazon Web Services
38// Signature Version 4)
39// (https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html).
40// Note: After you initiate multipart upload and upload one or more parts, you must
41// either complete or abort multipart upload in order to stop getting charged for
42// storage of the uploaded parts. Only after you either complete or abort multipart
43// upload, Amazon S3 frees up the parts storage and stops charging you for the
44// parts storage. For more information on multipart uploads, go to Multipart Upload
45// Overview (https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html) in
46// the Amazon S3 User Guide . For information on the permissions required to use
47// the multipart upload API, go to Multipart Upload and Permissions
48// (https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuAndPermissions.html) in the
49// Amazon S3 User Guide. You can optionally request server-side encryption where
50// Amazon S3 encrypts your data as it writes it to disks in its data centers and
51// decrypts it for you when you access it. You have the option of providing your
52// own encryption key, or you can use the Amazon Web Services managed encryption
53// keys. If you choose to provide your own encryption key, the request headers you
54// provide in the request must match the headers you used in the request to
55// initiate the upload by using CreateMultipartUpload
56// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html).
57// For more information, go to Using Server-Side Encryption
58// (https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html)
59// in the Amazon S3 User Guide. Server-side encryption is supported by the S3
60// Multipart Upload actions. Unless you are using a customer-provided encryption
61// key, you don't need to specify the encryption parameters in each UploadPart
62// request. Instead, you only need to specify the server-side encryption parameters
63// in the initial Initiate Multipart request. For more information, see
64// CreateMultipartUpload
65// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html).
66// If you requested server-side encryption using a customer-provided encryption key
67// in your initiate multipart upload request, you must provide identical encryption
68// information in each part upload using the following headers.
69//
70// *
71// x-amz-server-side-encryption-customer-algorithm
72//
73// *
74// x-amz-server-side-encryption-customer-key
75//
76// *
77// x-amz-server-side-encryption-customer-key-MD5
78//
79// Special Errors
80//
81// * Code:
82// NoSuchUpload
83//
84// * Cause: The specified multipart upload does not exist. The upload
85// ID might be invalid, or the multipart upload might have been aborted or
86// completed.
87//
88// * HTTP Status Code: 404 Not Found
89//
90// * SOAP Fault Code Prefix:
91// Client
92//
93// Related Resources
94//
95// * CreateMultipartUpload
96// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html)
97//
98// *
99// CompleteMultipartUpload
100// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html)
101//
102// *
103// AbortMultipartUpload
104// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_AbortMultipartUpload.html)
105//
106// *
107// ListParts
108// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListParts.html)
109//
110// *
111// ListMultipartUploads
112// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html)
113func (c *Client) UploadPart(ctx context.Context, params *UploadPartInput, optFns ...func(*Options)) (*UploadPartOutput, error) {
114	if params == nil {
115		params = &UploadPartInput{}
116	}
117
118	result, metadata, err := c.invokeOperation(ctx, "UploadPart", params, optFns, c.addOperationUploadPartMiddlewares)
119	if err != nil {
120		return nil, err
121	}
122
123	out := result.(*UploadPartOutput)
124	out.ResultMetadata = metadata
125	return out, nil
126}
127
128type UploadPartInput struct {
129
130	// The name of the bucket to which the multipart upload was initiated. When using
131	// this action with an access point, you must direct requests to the access point
132	// hostname. The access point hostname takes the form
133	// AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this
134	// action with an access point through the Amazon Web Services SDKs, you provide
135	// the access point ARN in place of the bucket name. For more information about
136	// access point ARNs, see Using access points
137	// (https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html)
138	// in the Amazon S3 User Guide. When using this action with Amazon S3 on Outposts,
139	// you must direct requests to the S3 on Outposts hostname. The S3 on Outposts
140	// hostname takes the form
141	// AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using
142	// this action using S3 on Outposts through the Amazon Web Services SDKs, you
143	// provide the Outposts bucket ARN in place of the bucket name. For more
144	// information about S3 on Outposts ARNs, see Using S3 on Outposts
145	// (https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3onOutposts.html) in the
146	// Amazon S3 User Guide.
147	//
148	// This member is required.
149	Bucket *string
150
151	// Object key for which the multipart upload was initiated.
152	//
153	// This member is required.
154	Key *string
155
156	// Part number of part being uploaded. This is a positive integer between 1 and
157	// 10,000.
158	//
159	// This member is required.
160	PartNumber int32
161
162	// Upload ID identifying the multipart upload whose part is being uploaded.
163	//
164	// This member is required.
165	UploadId *string
166
167	// Object data.
168	Body io.Reader
169
170	// Size of the body in bytes. This parameter is useful when the size of the body
171	// cannot be determined automatically.
172	ContentLength int64
173
174	// The base64-encoded 128-bit MD5 digest of the part data. This parameter is
175	// auto-populated when using the command from the CLI. This parameter is required
176	// if object lock parameters are specified.
177	ContentMD5 *string
178
179	// The account ID of the expected bucket owner. If the bucket is owned by a
180	// different account, the request will fail with an HTTP 403 (Access Denied) error.
181	ExpectedBucketOwner *string
182
183	// Confirms that the requester knows that they will be charged for the request.
184	// Bucket owners need not specify this parameter in their requests. For information
185	// about downloading objects from requester pays buckets, see Downloading Objects
186	// in Requestor Pays Buckets
187	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html)
188	// in the Amazon S3 User Guide.
189	RequestPayer types.RequestPayer
190
191	// Specifies the algorithm to use to when encrypting the object (for example,
192	// AES256).
193	SSECustomerAlgorithm *string
194
195	// Specifies the customer-provided encryption key for Amazon S3 to use in
196	// encrypting data. This value is used to store the object and then it is
197	// discarded; Amazon S3 does not store the encryption key. The key must be
198	// appropriate for use with the algorithm specified in the
199	// x-amz-server-side-encryption-customer-algorithm header. This must be the same
200	// encryption key specified in the initiate multipart upload request.
201	SSECustomerKey *string
202
203	// Specifies the 128-bit MD5 digest of the encryption key according to RFC 1321.
204	// Amazon S3 uses this header for a message integrity check to ensure that the
205	// encryption key was transmitted without error.
206	SSECustomerKeyMD5 *string
207
208	noSmithyDocumentSerde
209}
210
211type UploadPartOutput struct {
212
213	// Indicates whether the multipart upload uses an S3 Bucket Key for server-side
214	// encryption with Amazon Web Services KMS (SSE-KMS).
215	BucketKeyEnabled bool
216
217	// Entity tag for the uploaded object.
218	ETag *string
219
220	// If present, indicates that the requester was successfully charged for the
221	// request.
222	RequestCharged types.RequestCharged
223
224	// If server-side encryption with a customer-provided encryption key was requested,
225	// the response will include this header confirming the encryption algorithm used.
226	SSECustomerAlgorithm *string
227
228	// If server-side encryption with a customer-provided encryption key was requested,
229	// the response will include this header to provide round-trip message integrity
230	// verification of the customer-provided encryption key.
231	SSECustomerKeyMD5 *string
232
233	// If present, specifies the ID of the Amazon Web Services Key Management Service
234	// (Amazon Web Services KMS) symmetric customer managed key was used for the
235	// object.
236	SSEKMSKeyId *string
237
238	// The server-side encryption algorithm used when storing this object in Amazon S3
239	// (for example, AES256, aws:kms).
240	ServerSideEncryption types.ServerSideEncryption
241
242	// Metadata pertaining to the operation's result.
243	ResultMetadata middleware.Metadata
244
245	noSmithyDocumentSerde
246}
247
248func (c *Client) addOperationUploadPartMiddlewares(stack *middleware.Stack, options Options) (err error) {
249	err = stack.Serialize.Add(&awsRestxml_serializeOpUploadPart{}, middleware.After)
250	if err != nil {
251		return err
252	}
253	err = stack.Deserialize.Add(&awsRestxml_deserializeOpUploadPart{}, middleware.After)
254	if err != nil {
255		return err
256	}
257	if err = addSetLoggerMiddleware(stack, options); err != nil {
258		return err
259	}
260	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
261		return err
262	}
263	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
264		return err
265	}
266	if err = addResolveEndpointMiddleware(stack, options); err != nil {
267		return err
268	}
269	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
270		return err
271	}
272	if err = addRetryMiddlewares(stack, options); err != nil {
273		return err
274	}
275	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
276		return err
277	}
278	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
279		return err
280	}
281	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
282		return err
283	}
284	if err = addClientUserAgent(stack); err != nil {
285		return err
286	}
287	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
288		return err
289	}
290	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
291		return err
292	}
293	if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil {
294		return err
295	}
296	if err = addOpUploadPartValidationMiddleware(stack); err != nil {
297		return err
298	}
299	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opUploadPart(options.Region), middleware.Before); err != nil {
300		return err
301	}
302	if err = addMetadataRetrieverMiddleware(stack); err != nil {
303		return err
304	}
305	if err = addUploadPartUpdateEndpoint(stack, options); err != nil {
306		return err
307	}
308	if err = addResponseErrorMiddleware(stack); err != nil {
309		return err
310	}
311	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
312		return err
313	}
314	if err = disableAcceptEncodingGzip(stack); err != nil {
315		return err
316	}
317	if err = addRequestResponseLogging(stack, options); err != nil {
318		return err
319	}
320	return nil
321}
322
323func newServiceMetadataMiddleware_opUploadPart(region string) *awsmiddleware.RegisterServiceMetadata {
324	return &awsmiddleware.RegisterServiceMetadata{
325		Region:        region,
326		ServiceID:     ServiceID,
327		SigningName:   "s3",
328		OperationName: "UploadPart",
329	}
330}
331
332// getUploadPartBucketMember returns a pointer to string denoting a provided bucket
333// member valueand a boolean indicating if the input has a modeled bucket name,
334func getUploadPartBucketMember(input interface{}) (*string, bool) {
335	in := input.(*UploadPartInput)
336	if in.Bucket == nil {
337		return nil, false
338	}
339	return in.Bucket, true
340}
341func addUploadPartUpdateEndpoint(stack *middleware.Stack, options Options) error {
342	return s3cust.UpdateEndpoint(stack, s3cust.UpdateEndpointOptions{
343		Accessor: s3cust.UpdateEndpointParameterAccessor{
344			GetBucketFromInput: getUploadPartBucketMember,
345		},
346		UsePathStyle:                   options.UsePathStyle,
347		UseAccelerate:                  options.UseAccelerate,
348		SupportsAccelerate:             true,
349		TargetS3ObjectLambda:           false,
350		EndpointResolver:               options.EndpointResolver,
351		EndpointResolverOptions:        options.EndpointOptions,
352		UseDualstack:                   options.UseDualstack,
353		UseARNRegion:                   options.UseARNRegion,
354		DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints,
355	})
356}
357
358// PresignUploadPart is used to generate a presigned HTTP Request which contains
359// presigned URL, signed headers and HTTP method used.
360func (c *PresignClient) PresignUploadPart(ctx context.Context, params *UploadPartInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error) {
361	if params == nil {
362		params = &UploadPartInput{}
363	}
364	options := c.options.copy()
365	for _, fn := range optFns {
366		fn(&options)
367	}
368	clientOptFns := append(options.ClientOptions, withNopHTTPClientAPIOption)
369
370	result, _, err := c.client.invokeOperation(ctx, "UploadPart", params, clientOptFns,
371		c.client.addOperationUploadPartMiddlewares,
372		presignConverter(options).convertToPresignMiddleware,
373		func(stack *middleware.Stack, options Options) error {
374			return awshttp.RemoveContentTypeHeader(stack)
375		},
376		addUploadPartPayloadAsUnsigned,
377	)
378	if err != nil {
379		return nil, err
380	}
381
382	out := result.(*v4.PresignedHTTPRequest)
383	return out, nil
384}
385
386func addUploadPartPayloadAsUnsigned(stack *middleware.Stack, options Options) error {
387	v4.RemoveContentSHA256HeaderMiddleware(stack)
388	v4.RemoveComputePayloadSHA256Middleware(stack)
389	return v4.AddUnsignedPayloadMiddleware(stack)
390}
391