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 "time" 15) 16 17// Retrieves objects from Amazon S3. To use GET, you must have READ access to the 18// object. If you grant READ access to the anonymous user, you can return the 19// object without using an authorization header. An Amazon S3 bucket has no 20// directory hierarchy such as you would find in a typical computer file system. 21// You can, however, create a logical hierarchy by using object key names that 22// imply a folder structure. For example, instead of naming an object sample.jpg, 23// you can name it photos/2006/February/sample.jpg. To get an object from such a 24// logical hierarchy, specify the full key name for the object in the GET 25// operation. For a virtual hosted-style request example, if you have the object 26// photos/2006/February/sample.jpg, specify the resource as 27// /photos/2006/February/sample.jpg. For a path-style request example, if you have 28// the object photos/2006/February/sample.jpg in the bucket named examplebucket, 29// specify the resource as /examplebucket/photos/2006/February/sample.jpg. For more 30// information about request types, see HTTP Host Header Bucket Specification 31// (https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html#VirtualHostingSpecifyBucket). 32// To distribute large files to many people, you can save bandwidth costs by using 33// BitTorrent. For more information, see Amazon S3 Torrent 34// (https://docs.aws.amazon.com/AmazonS3/latest/dev/S3Torrent.html). For more 35// information about returning the ACL of an object, see GetObjectAcl 36// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectAcl.html). If the 37// object you are retrieving is stored in the S3 Glacier or S3 Glacier Deep Archive 38// storage class, or S3 Intelligent-Tiering Archive or S3 Intelligent-Tiering Deep 39// Archive tiers, before you can retrieve the object you must first restore a copy 40// using RestoreObject 41// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_RestoreObject.html). 42// Otherwise, this action returns an InvalidObjectStateError error. For information 43// about restoring archived objects, see Restoring Archived Objects 44// (https://docs.aws.amazon.com/AmazonS3/latest/dev/restoring-objects.html). 45// Encryption request headers, like x-amz-server-side-encryption, should not be 46// sent for GET requests if your object uses server-side encryption with CMKs 47// stored in AWS KMS (SSE-KMS) or server-side encryption with Amazon S3–managed 48// encryption keys (SSE-S3). If your object does use these types of keys, you’ll 49// get an HTTP 400 BadRequest error. If you encrypt an object by using server-side 50// encryption with customer-provided encryption keys (SSE-C) when you store the 51// object in Amazon S3, then when you GET the object, you must use the following 52// headers: 53// 54// * x-amz-server-side-encryption-customer-algorithm 55// 56// * 57// x-amz-server-side-encryption-customer-key 58// 59// * 60// x-amz-server-side-encryption-customer-key-MD5 61// 62// For more information about SSE-C, 63// see Server-Side Encryption (Using Customer-Provided Encryption Keys) 64// (https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerSideEncryptionCustomerKeys.html). 65// Assuming you have permission to read object tags (permission for the 66// s3:GetObjectVersionTagging action), the response also returns the 67// x-amz-tagging-count header that provides the count of number of tags associated 68// with the object. You can use GetObjectTagging 69// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectTagging.html) to 70// retrieve the tag set associated with an object. Permissions You need the 71// s3:GetObject permission for this operation. For more information, see Specifying 72// Permissions in a Policy 73// (https://docs.aws.amazon.com/AmazonS3/latest/dev/using-with-s3-actions.html). If 74// the object you request does not exist, the error Amazon S3 returns depends on 75// whether you also have the s3:ListBucket permission. 76// 77// * If you have the 78// s3:ListBucket permission on the bucket, Amazon S3 will return an HTTP status 79// code 404 ("no such key") error. 80// 81// * If you don’t have the s3:ListBucket 82// permission, Amazon S3 will return an HTTP status code 403 ("access denied") 83// error. 84// 85// Versioning By default, the GET action returns the current version of an 86// object. To return a different version, use the versionId subresource. If the 87// current version of the object is a delete marker, Amazon S3 behaves as if the 88// object was deleted and includes x-amz-delete-marker: true in the response. For 89// more information about versioning, see PutBucketVersioning 90// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketVersioning.html). 91// Overriding Response Header Values There are times when you want to override 92// certain response header values in a GET response. For example, you might 93// override the Content-Disposition response header value in your GET request. You 94// can override values for a set of response headers using the following query 95// parameters. These response header values are sent only on a successful request, 96// that is, when status code 200 OK is returned. The set of headers you can 97// override using these parameters is a subset of the headers that Amazon S3 98// accepts when you create an object. The response headers that you can override 99// for the GET response are Content-Type, Content-Language, Expires, Cache-Control, 100// Content-Disposition, and Content-Encoding. To override these header values in 101// the GET response, you use the following request parameters. You must sign the 102// request, either using an Authorization header or a presigned URL, when using 103// these parameters. They cannot be used with an unsigned (anonymous) request. 104// 105// * 106// response-content-type 107// 108// * response-content-language 109// 110// * response-expires 111// 112// * 113// response-cache-control 114// 115// * response-content-disposition 116// 117// * 118// response-content-encoding 119// 120// Additional Considerations about Request Headers If 121// both of the If-Match and If-Unmodified-Since headers are present in the request 122// as follows: If-Match condition evaluates to true, and; If-Unmodified-Since 123// condition evaluates to false; then, S3 returns 200 OK and the data requested. If 124// both of the If-None-Match and If-Modified-Since headers are present in the 125// request as follows: If-None-Match condition evaluates to false, and; 126// If-Modified-Since condition evaluates to true; then, S3 returns 304 Not Modified 127// response code. For more information about conditional requests, see RFC 7232 128// (https://tools.ietf.org/html/rfc7232). The following operations are related to 129// GetObject: 130// 131// * ListBuckets 132// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBuckets.html) 133// 134// * 135// GetObjectAcl 136// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectAcl.html) 137func (c *Client) GetObject(ctx context.Context, params *GetObjectInput, optFns ...func(*Options)) (*GetObjectOutput, error) { 138 if params == nil { 139 params = &GetObjectInput{} 140 } 141 142 result, metadata, err := c.invokeOperation(ctx, "GetObject", params, optFns, addOperationGetObjectMiddlewares) 143 if err != nil { 144 return nil, err 145 } 146 147 out := result.(*GetObjectOutput) 148 out.ResultMetadata = metadata 149 return out, nil 150} 151 152type GetObjectInput struct { 153 154 // The bucket name containing the object. When using this action with an access 155 // point, you must direct requests to the access point hostname. The access point 156 // hostname takes the form 157 // AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this 158 // action with an access point through the AWS SDKs, you provide the access point 159 // ARN in place of the bucket name. For more information about access point ARNs, 160 // see Using Access Points 161 // (https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html) 162 // in the Amazon S3 User Guide. When using this action with Amazon S3 on Outposts, 163 // you must direct requests to the S3 on Outposts hostname. The S3 on Outposts 164 // hostname takes the form 165 // AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using 166 // this action using S3 on Outposts through the AWS SDKs, you provide the Outposts 167 // bucket ARN in place of the bucket name. For more information about S3 on 168 // Outposts ARNs, see Using S3 on Outposts 169 // (https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3onOutposts.html) in the 170 // Amazon S3 User Guide. 171 // 172 // This member is required. 173 Bucket *string 174 175 // Key of the object to get. 176 // 177 // This member is required. 178 Key *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 // Return the object only if its entity tag (ETag) is the same as the one 185 // specified, otherwise return a 412 (precondition failed). 186 IfMatch *string 187 188 // Return the object only if it has been modified since the specified time, 189 // otherwise return a 304 (not modified). 190 IfModifiedSince *time.Time 191 192 // Return the object only if its entity tag (ETag) is different from the one 193 // specified, otherwise return a 304 (not modified). 194 IfNoneMatch *string 195 196 // Return the object only if it has not been modified since the specified time, 197 // otherwise return a 412 (precondition failed). 198 IfUnmodifiedSince *time.Time 199 200 // Part number of the object being read. This is a positive integer between 1 and 201 // 10,000. Effectively performs a 'ranged' GET request for the part specified. 202 // Useful for downloading just a part of an object. 203 PartNumber int32 204 205 // Downloads the specified range bytes of an object. For more information about the 206 // HTTP Range header, see 207 // https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 208 // (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35). Amazon S3 209 // doesn't support retrieving multiple ranges of data per GET request. 210 Range *string 211 212 // Confirms that the requester knows that they will be charged for the request. 213 // Bucket owners need not specify this parameter in their requests. For information 214 // about downloading objects from requester pays buckets, see Downloading Objects 215 // in Requestor Pays Buckets 216 // (https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html) 217 // in the Amazon S3 Developer Guide. 218 RequestPayer types.RequestPayer 219 220 // Sets the Cache-Control header of the response. 221 ResponseCacheControl *string 222 223 // Sets the Content-Disposition header of the response 224 ResponseContentDisposition *string 225 226 // Sets the Content-Encoding header of the response. 227 ResponseContentEncoding *string 228 229 // Sets the Content-Language header of the response. 230 ResponseContentLanguage *string 231 232 // Sets the Content-Type header of the response. 233 ResponseContentType *string 234 235 // Sets the Expires header of the response. 236 ResponseExpires *time.Time 237 238 // Specifies the algorithm to use to when decrypting the object (for example, 239 // AES256). 240 SSECustomerAlgorithm *string 241 242 // Specifies the customer-provided encryption key for Amazon S3 used to encrypt the 243 // data. This value is used to decrypt the object when recovering it and must match 244 // the one used when storing the data. The key must be appropriate for use with the 245 // algorithm specified in the x-amz-server-side-encryption-customer-algorithm 246 // header. 247 SSECustomerKey *string 248 249 // Specifies the 128-bit MD5 digest of the encryption key according to RFC 1321. 250 // Amazon S3 uses this header for a message integrity check to ensure that the 251 // encryption key was transmitted without error. 252 SSECustomerKeyMD5 *string 253 254 // VersionId used to reference a specific version of the object. 255 VersionId *string 256} 257 258type GetObjectOutput struct { 259 260 // Indicates that a range of bytes was specified. 261 AcceptRanges *string 262 263 // Object data. 264 Body io.ReadCloser 265 266 // Indicates whether the object uses an S3 Bucket Key for server-side encryption 267 // with AWS KMS (SSE-KMS). 268 BucketKeyEnabled bool 269 270 // Specifies caching behavior along the request/reply chain. 271 CacheControl *string 272 273 // Specifies presentational information for the object. 274 ContentDisposition *string 275 276 // Specifies what content encodings have been applied to the object and thus what 277 // decoding mechanisms must be applied to obtain the media-type referenced by the 278 // Content-Type header field. 279 ContentEncoding *string 280 281 // The language the content is in. 282 ContentLanguage *string 283 284 // Size of the body in bytes. 285 ContentLength int64 286 287 // The portion of the object returned in the response. 288 ContentRange *string 289 290 // A standard MIME type describing the format of the object data. 291 ContentType *string 292 293 // Specifies whether the object retrieved was (true) or was not (false) a Delete 294 // Marker. If false, this response header does not appear in the response. 295 DeleteMarker bool 296 297 // An ETag is an opaque identifier assigned by a web server to a specific version 298 // of a resource found at a URL. 299 ETag *string 300 301 // If the object expiration is configured (see PUT Bucket lifecycle), the response 302 // includes this header. It includes the expiry-date and rule-id key-value pairs 303 // providing object expiration information. The value of the rule-id is URL 304 // encoded. 305 Expiration *string 306 307 // The date and time at which the object is no longer cacheable. 308 Expires *time.Time 309 310 // Creation date of the object. 311 LastModified *time.Time 312 313 // A map of metadata to store with the object in S3. 314 // 315 // Map keys will be normalized to lower-case. 316 Metadata map[string]string 317 318 // This is set to the number of metadata entries not returned in x-amz-meta 319 // headers. This can happen if you create metadata using an API like SOAP that 320 // supports more flexible metadata than the REST API. For example, using SOAP, you 321 // can create metadata whose values are not legal HTTP headers. 322 MissingMeta int32 323 324 // Indicates whether this object has an active legal hold. This field is only 325 // returned if you have permission to view an object's legal hold status. 326 ObjectLockLegalHoldStatus types.ObjectLockLegalHoldStatus 327 328 // The Object Lock mode currently in place for this object. 329 ObjectLockMode types.ObjectLockMode 330 331 // The date and time when this object's Object Lock will expire. 332 ObjectLockRetainUntilDate *time.Time 333 334 // The count of parts this object has. 335 PartsCount int32 336 337 // Amazon S3 can return this if your request involves a bucket that is either a 338 // source or destination in a replication rule. 339 ReplicationStatus types.ReplicationStatus 340 341 // If present, indicates that the requester was successfully charged for the 342 // request. 343 RequestCharged types.RequestCharged 344 345 // Provides information about object restoration action and expiration time of the 346 // restored object copy. 347 Restore *string 348 349 // If server-side encryption with a customer-provided encryption key was requested, 350 // the response will include this header confirming the encryption algorithm used. 351 SSECustomerAlgorithm *string 352 353 // If server-side encryption with a customer-provided encryption key was requested, 354 // the response will include this header to provide round-trip message integrity 355 // verification of the customer-provided encryption key. 356 SSECustomerKeyMD5 *string 357 358 // If present, specifies the ID of the AWS Key Management Service (AWS KMS) 359 // symmetric customer managed customer master key (CMK) that was used for the 360 // object. 361 SSEKMSKeyId *string 362 363 // The server-side encryption algorithm used when storing this object in Amazon S3 364 // (for example, AES256, aws:kms). 365 ServerSideEncryption types.ServerSideEncryption 366 367 // Provides storage class information of the object. Amazon S3 returns this header 368 // for all objects except for S3 Standard storage class objects. 369 StorageClass types.StorageClass 370 371 // The number of tags, if any, on the object. 372 TagCount int32 373 374 // Version of the object. 375 VersionId *string 376 377 // If the bucket is configured as a website, redirects requests for this object to 378 // another object in the same bucket or to an external URL. Amazon S3 stores the 379 // value of this header in the object metadata. 380 WebsiteRedirectLocation *string 381 382 // Metadata pertaining to the operation's result. 383 ResultMetadata middleware.Metadata 384} 385 386func addOperationGetObjectMiddlewares(stack *middleware.Stack, options Options) (err error) { 387 err = stack.Serialize.Add(&awsRestxml_serializeOpGetObject{}, middleware.After) 388 if err != nil { 389 return err 390 } 391 err = stack.Deserialize.Add(&awsRestxml_deserializeOpGetObject{}, middleware.After) 392 if err != nil { 393 return err 394 } 395 if err = addSetLoggerMiddleware(stack, options); err != nil { 396 return err 397 } 398 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 399 return err 400 } 401 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 402 return err 403 } 404 if err = addResolveEndpointMiddleware(stack, options); err != nil { 405 return err 406 } 407 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 408 return err 409 } 410 if err = addRetryMiddlewares(stack, options); err != nil { 411 return err 412 } 413 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 414 return err 415 } 416 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 417 return err 418 } 419 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 420 return err 421 } 422 if err = addClientUserAgent(stack); err != nil { 423 return err 424 } 425 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 426 return err 427 } 428 if err = addOpGetObjectValidationMiddleware(stack); err != nil { 429 return err 430 } 431 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetObject(options.Region), middleware.Before); err != nil { 432 return err 433 } 434 if err = addMetadataRetrieverMiddleware(stack); err != nil { 435 return err 436 } 437 if err = addGetObjectUpdateEndpoint(stack, options); err != nil { 438 return err 439 } 440 if err = addResponseErrorMiddleware(stack); err != nil { 441 return err 442 } 443 if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil { 444 return err 445 } 446 if err = disableAcceptEncodingGzip(stack); err != nil { 447 return err 448 } 449 if err = addRequestResponseLogging(stack, options); err != nil { 450 return err 451 } 452 return nil 453} 454 455func newServiceMetadataMiddleware_opGetObject(region string) *awsmiddleware.RegisterServiceMetadata { 456 return &awsmiddleware.RegisterServiceMetadata{ 457 Region: region, 458 ServiceID: ServiceID, 459 SigningName: "s3", 460 OperationName: "GetObject", 461 } 462} 463 464// getGetObjectBucketMember returns a pointer to string denoting a provided bucket 465// member valueand a boolean indicating if the input has a modeled bucket name, 466func getGetObjectBucketMember(input interface{}) (*string, bool) { 467 in := input.(*GetObjectInput) 468 if in.Bucket == nil { 469 return nil, false 470 } 471 return in.Bucket, true 472} 473func addGetObjectUpdateEndpoint(stack *middleware.Stack, options Options) error { 474 return s3cust.UpdateEndpoint(stack, s3cust.UpdateEndpointOptions{ 475 Accessor: s3cust.UpdateEndpointParameterAccessor{ 476 GetBucketFromInput: getGetObjectBucketMember, 477 }, 478 UsePathStyle: options.UsePathStyle, 479 UseAccelerate: options.UseAccelerate, 480 SupportsAccelerate: true, 481 TargetS3ObjectLambda: false, 482 EndpointResolver: options.EndpointResolver, 483 EndpointResolverOptions: options.EndpointOptions, 484 UseDualstack: options.UseDualstack, 485 UseARNRegion: options.UseARNRegion, 486 }) 487} 488 489// PresignGetObject is used to generate a presigned HTTP Request which contains 490// presigned URL, signed headers and HTTP method used. 491func (c *PresignClient) PresignGetObject(ctx context.Context, params *GetObjectInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error) { 492 if params == nil { 493 params = &GetObjectInput{} 494 } 495 options := c.options.copy() 496 for _, fn := range optFns { 497 fn(&options) 498 } 499 clientOptFns := append(options.ClientOptions, withNopHTTPClientAPIOption) 500 501 result, _, err := c.client.invokeOperation(ctx, "GetObject", params, clientOptFns, 502 addOperationGetObjectMiddlewares, 503 presignConverter(options).convertToPresignMiddleware, 504 addGetObjectPayloadAsUnsigned, 505 ) 506 if err != nil { 507 return nil, err 508 } 509 510 out := result.(*v4.PresignedHTTPRequest) 511 return out, nil 512} 513 514func addGetObjectPayloadAsUnsigned(stack *middleware.Stack, options Options) error { 515 v4.RemoveContentSHA256HeaderMiddleware(stack) 516 v4.RemoveComputePayloadSHA256Middleware(stack) 517 return v4.AddUnsignedPayloadMiddleware(stack) 518} 519