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