// Uploads a file to S3 given a bucket and object key. Also takes a duration // value to terminate the update if it doesn't complete within that time. // // The AWS Region needs to be provided in the AWS shared config or on the // environment variable as `AWS_REGION`. Credentials also must be provided // Will default to shared config file, but can load from environment if provided. // // Usage: // # Upload myfile.txt to myBucket/myKey. Must complete within 10 minutes or will fail // go run withContext.go -b mybucket -k myKey -d 10m < myfile.txt funcmain() { var bucket, key string var timeout time.Duration
// All clients require a Session. The Session provides the client with // shared configuration such as region, endpoint, and credentials. A // Session should be shared where possible to take advantage of // configuration and credential caching. See the session package for // more information. sess := session.Must(session.NewSession())
// Create a new instance of the service's client with a Session. // Optional aws.Config values can also be provided as variadic arguments // to the New function. This option allows you to provide service // specific configuration. svc := s3.New(sess)
// Create a context with a timeout that will abort the upload if it takes // more than the passed in timeout. ctx := context.Background() var cancelFn func() if timeout > 0 { ctx, cancelFn = context.WithTimeout(ctx, timeout) } // Ensure the context is canceled to prevent leaking. // See context package for more information, https://golang.org/pkg/context/ if cancelFn != nil { defer cancelFn() }
// Uploads the object to S3. The Context will interrupt the request if the // timeout expires. _, err := svc.PutObjectWithContext(ctx, &s3.PutObjectInput{ Bucket: aws.String(bucket), Key: aws.String(key), Body: os.Stdin, }) if err != nil { if aerr, ok := err.(awserr.Error); ok && aerr.Code() == request.CanceledErrorCode { // If the SDK can determine the request or retry delay was canceled // by a context the CanceledErrorCode error code will be returned. fmt.Fprintf(os.Stderr, "upload canceled due to timeout, %v\n", err) } else { fmt.Fprintf(os.Stderr, "failed to upload object, %v\n", err) } os.Exit(1) }
fmt.Printf("successfully uploaded file to %s/%s\n", bucket, key) }
funcmain() { // Using the SDK's default configuration, loading additional config // and credentials values from the environment variables, shared // credentials, and shared configuration files cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-west-2")) if err != nil { log.Fatalf("unable to load SDK config, %v", err) }
// Using the Config value, create the DynamoDB client svc := dynamodb.NewFromConfig(cfg)
// Build the request with its input parameters resp, err := svc.ListTables(context.TODO(), &dynamodb.ListTablesInput{ Limit: aws.Int32(5), }) if err != nil { log.Fatalf("failed to list tables, %v", err) }
fmt.Println("Tables:") for _, tableName := range resp.TableNames { fmt.Println(tableName) } }
// 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. You cannot use // PutObject to only update a single piece of metadata for an existing object. You // must put the entire object with updated metadata if you want to update some // values. 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. To prevent objects from being deleted or overwritten, you can // use Amazon S3 Object Lock (https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock.html) // . 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. // - To successfully complete the PutObject request, you must have the // s3:PutObject in your IAM permissions. // - To successfully change the objects acl of your PutObject request, you must // have the s3:PutObjectAcl in your IAM permissions. // - To successfully set the tag-set with your PutObject request, you must have // the s3:PutObjectTagging in your IAM permissions. // - The Content-MD5 header is required for any request to upload an object with // a retention period configured using Amazon S3 Object Lock. For more information // about Amazon S3 Object Lock, see Amazon S3 Object Lock Overview (https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock-overview.html) // in the Amazon S3 User Guide. // // You have three mutually exclusive options to protect data using server-side // encryption in Amazon S3, depending on how you choose to manage the encryption // keys. Specifically, the encryption key options are Amazon S3 managed keys // (SSE-S3), Amazon Web Services KMS keys (SSE-KMS), and customer-provided keys // (SSE-C). Amazon S3 encrypts data with server-side encryption by using Amazon S3 // managed keys (SSE-S3) by default. You can optionally tell Amazon S3 to encrypt // data at by rest using server-side encryption with other key options. For more // information, see Using Server-Side Encryption (https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html) // . When adding a new object, you can use headers to grant ACL-based permissions // to individual Amazon Web Services accounts or to predefined groups defined by // Amazon S3. These permissions are then added to the ACL on the object. By // default, all objects are private. Only the owner has full access control. For // more information, see Access Control List (ACL) Overview (https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html) // and Managing ACLs Using the REST API (https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-using-rest-api.html) // . If the bucket that you're uploading objects to uses the bucket owner enforced // setting for S3 Object Ownership, ACLs are disabled and no longer affect // permissions. Buckets that use this setting only accept PUT requests that don't // specify an ACL or PUT requests that specify bucket owner full control ACLs, such // as the bucket-owner-full-control canned ACL or an equivalent form of this ACL // expressed in the XML format. PUT requests that contain other ACLs (for example, // custom grants to certain Amazon Web Services accounts) fail and return a 400 // error with the error code AccessControlListNotSupported . For more information, // see Controlling ownership of objects and disabling ACLs (https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html) // in the Amazon S3 User Guide. If your bucket uses the bucket owner enforced // setting for Object Ownership, all objects written to the bucket by any account // will be owned by the bucket owner. By default, Amazon S3 uses the STANDARD // Storage Class to store newly created objects. The STANDARD storage class // provides high durability and high availability. Depending on performance needs, // you can specify a different Storage Class. Amazon S3 on Outposts only uses the // OUTPOSTS Storage Class. For more information, see Storage Classes (https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html) // in the Amazon S3 User Guide. 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. When you enable versioning for a bucket, if // Amazon S3 receives multiple write requests for the same object simultaneously, // it stores all of the objects. For more information about versioning, see Adding // Objects to Versioning-Enabled Buckets (https://docs.aws.amazon.com/AmazonS3/latest/dev/AddingObjectstoVersioningEnabledBuckets.html) // . For information about returning the versioning state of a bucket, see // GetBucketVersioning (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketVersioning.html) // . For more information about related Amazon S3 APIs, see the following: // - CopyObject (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html) // - DeleteObject (https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html) func(c *Client) PutObject(ctx context.Context, params *PutObjectInput, optFns ...func(*Options)) (*PutObjectOutput, error) { if params == nil { params = &PutObjectInput{} }
// The bucket name to which the PUT action was initiated. When using this action // with an access point, you must direct requests to the access point hostname. The // access point hostname takes the form // AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this // action with an access point through the Amazon Web Services SDKs, you provide // the access point ARN in place of the bucket name. For more information about // access point ARNs, see Using access points (https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html) // in the Amazon S3 User Guide. When you use this action with Amazon S3 on // Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on // Outposts hostname takes the form // AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com . When you // use this action with S3 on Outposts through the Amazon Web Services SDKs, you // provide the Outposts access point ARN in place of the bucket name. For more // information about S3 on Outposts ARNs, see What is S3 on Outposts (https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3onOutposts.html) // in the Amazon S3 User Guide. // // This member is required. Bucket *string
// Object key for which the PUT action was initiated. // // This member is required. Key *string
// The canned ACL to apply to the object. For more information, see Canned ACL (https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#CannedACL) // . This action is not supported by Amazon S3 on Outposts. ACL types.ObjectCannedACL
// Object data. Body io.Reader
// Specifies whether Amazon S3 should use an S3 Bucket Key for object encryption // with server-side encryption using AWS KMS (SSE-KMS). Setting this header to true // causes Amazon S3 to use an S3 Bucket Key for object encryption with SSE-KMS. // Specifying this header with a PUT action doesn’t affect bucket-level settings // for S3 Bucket Key. BucketKeyEnabled bool
// Can be used to specify caching behavior along the request/reply chain. For more // information, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) // . CacheControl *string
// Indicates the algorithm used to create the checksum for the object when using // the SDK. This header will not provide any additional functionality if not using // the SDK. When sending this header, there must be a corresponding x-amz-checksum // or x-amz-trailer header sent. Otherwise, Amazon S3 fails the request with the // HTTP status code 400 Bad Request . For more information, see Checking object // integrity (https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html) // in the Amazon S3 User Guide. If you provide an individual checksum, Amazon S3 // ignores any provided ChecksumAlgorithm parameter. ChecksumAlgorithm types.ChecksumAlgorithm
// This header can be used as a data integrity check to verify that the data // received is the same data that was originally sent. This header specifies the // base64-encoded, 32-bit CRC32 checksum of the object. For more information, see // Checking object integrity (https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html) // in the Amazon S3 User Guide. ChecksumCRC32 *string
// This header can be used as a data integrity check to verify that the data // received is the same data that was originally sent. This header specifies the // base64-encoded, 32-bit CRC32C checksum of the object. For more information, see // Checking object integrity (https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html) // in the Amazon S3 User Guide. ChecksumCRC32C *string
// This header can be used as a data integrity check to verify that the data // received is the same data that was originally sent. This header specifies the // base64-encoded, 160-bit SHA-1 digest of the object. For more information, see // Checking object integrity (https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html) // in the Amazon S3 User Guide. ChecksumSHA1 *string
// This header can be used as a data integrity check to verify that the data // received is the same data that was originally sent. This header specifies the // base64-encoded, 256-bit SHA-256 digest of the object. For more information, see // Checking object integrity (https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html) // in the Amazon S3 User Guide. ChecksumSHA256 *string
// Specifies presentational information for the object. For more information, see // https://www.rfc-editor.org/rfc/rfc6266#section-4 (https://www.rfc-editor.org/rfc/rfc6266#section-4) // . ContentDisposition *string
// Specifies what content encodings have been applied to the object and thus what // decoding mechanisms must be applied to obtain the media-type referenced by the // Content-Type header field. For more information, see // https://www.rfc-editor.org/rfc/rfc9110.html#field.content-encoding (https://www.rfc-editor.org/rfc/rfc9110.html#field.content-encoding) // . ContentEncoding *string
// The language the content is in. ContentLanguage *string
// Size of the body in bytes. This parameter is useful when the size of the body // cannot be determined automatically. For more information, see // https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length (https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length) // . ContentLength int64
// The base64-encoded 128-bit MD5 digest of the message (without the headers) // according to RFC 1864. This header can be used as a message integrity check to // verify that the data is the same data that was originally sent. Although it is // optional, we recommend using the Content-MD5 mechanism as an end-to-end // integrity check. For more information about REST request authentication, see // REST Authentication (https://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html) // . ContentMD5 *string
// A standard MIME type describing the format of the contents. For more // information, see https://www.rfc-editor.org/rfc/rfc9110.html#name-content-type (https://www.rfc-editor.org/rfc/rfc9110.html#name-content-type) // . ContentType *string
// The account ID of the expected bucket owner. If the bucket is owned by a // different account, the request fails with the HTTP status code 403 Forbidden // (access denied). ExpectedBucketOwner *string
// The date and time at which the object is no longer cacheable. For more // information, see https://www.rfc-editor.org/rfc/rfc7234#section-5.3 (https://www.rfc-editor.org/rfc/rfc7234#section-5.3) // . Expires *time.Time
// Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. This // action is not supported by Amazon S3 on Outposts. GrantFullControl *string
// Allows grantee to read the object data and its metadata. This action is not // supported by Amazon S3 on Outposts. GrantRead *string
// Allows grantee to read the object ACL. This action is not supported by Amazon // S3 on Outposts. GrantReadACP *string
// Allows grantee to write the ACL for the applicable object. This action is not // supported by Amazon S3 on Outposts. GrantWriteACP *string
// A map of metadata to store with the object in S3. Metadata map[string]string
// Specifies whether a legal hold will be applied to this object. For more // information about S3 Object Lock, see Object Lock (https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock.html) // . ObjectLockLegalHoldStatus types.ObjectLockLegalHoldStatus
// The Object Lock mode that you want to apply to this object. ObjectLockMode types.ObjectLockMode
// The date and time when you want this object's Object Lock to expire. Must be // formatted as a timestamp parameter. ObjectLockRetainUntilDate *time.Time
// Confirms that the requester knows that they will be charged for the request. // Bucket owners need not specify this parameter in their requests. For information // about downloading objects from Requester Pays buckets, see Downloading Objects // in Requester Pays Buckets (https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html) // in the Amazon S3 User Guide. RequestPayer types.RequestPayer
// Specifies the algorithm to use to when encrypting the object (for example, // AES256). SSECustomerAlgorithm *string
// Specifies the customer-provided encryption key for Amazon S3 to use in // encrypting data. This value is used to store the object and then it is // discarded; Amazon S3 does not store the encryption key. The key must be // appropriate for use with the algorithm specified in the // x-amz-server-side-encryption-customer-algorithm header. SSECustomerKey *string
// Specifies the 128-bit MD5 digest of the encryption key according to RFC 1321. // Amazon S3 uses this header for a message integrity check to ensure that the // encryption key was transmitted without error. SSECustomerKeyMD5 *string
// Specifies the Amazon Web Services KMS Encryption Context to use for object // encryption. The value of this header is a base64-encoded UTF-8 string holding // JSON with the encryption context key-value pairs. This value is stored as object // metadata and automatically gets passed on to Amazon Web Services KMS for future // GetObject or CopyObject operations on this object. SSEKMSEncryptionContext *string
// If x-amz-server-side-encryption has a valid value of aws:kms , this header // specifies the ID of the Amazon Web Services Key Management Service (Amazon Web // Services KMS) symmetric encryption customer managed key that was used for the // object. If you specify x-amz-server-side-encryption:aws:kms , but do not provide // x-amz-server-side-encryption-aws-kms-key-id , Amazon S3 uses the Amazon Web // Services managed key to protect the data. If the KMS key does not exist in the // same account issuing the command, you must use the full ARN and not just the ID. SSEKMSKeyId *string
// The server-side encryption algorithm used when storing this object in Amazon S3 // (for example, AES256, aws:kms ). ServerSideEncryption types.ServerSideEncryption
// By default, Amazon S3 uses the STANDARD Storage Class to store newly created // objects. The STANDARD storage class provides high durability and high // availability. Depending on performance needs, you can specify a different // Storage Class. Amazon S3 on Outposts only uses the OUTPOSTS Storage Class. For // more information, see Storage Classes (https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html) // in the Amazon S3 User Guide. StorageClass types.StorageClass
// The tag-set for the object. The tag-set must be encoded as URL Query // parameters. (For example, "Key1=Value1") Tagging *string
// If the bucket is configured as a website, redirects requests for this object to // another object in the same bucket or to an external URL. Amazon S3 stores the // value of this header in the object metadata. For information about object // metadata, see Object Key and Metadata (https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html) // . In the following example, the request header sets the redirect to an object // (anotherPage.html) in the same bucket: x-amz-website-redirect-location: // /anotherPage.html In the following example, the request header sets the object // redirect to another website: x-amz-website-redirect-location: // http://www.example.com/ For more information about website hosting in Amazon S3, // see Hosting Websites on Amazon S3 (https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html) // and How to Configure Website Page Redirects (https://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html) // . WebsiteRedirectLocation *string
// Retrieves objects from Amazon S3. To use GET , you must have READ access to the // object. If you grant READ access to the anonymous user, you can return the // object without using an authorization header. An Amazon S3 bucket has no // directory hierarchy such as you would find in a typical computer file system. // You can, however, create a logical hierarchy by using object key names that // imply a folder structure. For example, instead of naming an object sample.jpg , // you can name it photos/2006/February/sample.jpg . To get an object from such a // logical hierarchy, specify the full key name for the object in the GET // operation. For a virtual hosted-style request example, if you have the object // photos/2006/February/sample.jpg , specify the resource as // /photos/2006/February/sample.jpg . For a path-style request example, if you have // the object photos/2006/February/sample.jpg in the bucket named examplebucket , // specify the resource as /examplebucket/photos/2006/February/sample.jpg . For // more information about request types, see HTTP Host Header Bucket Specification (https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html#VirtualHostingSpecifyBucket) // . For more information about returning the ACL of an object, see GetObjectAcl (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectAcl.html) // . If the object you are retrieving is stored in the S3 Glacier or S3 Glacier // Deep Archive storage class, or S3 Intelligent-Tiering Archive or S3 // Intelligent-Tiering Deep Archive tiers, before you can retrieve the object you // must first restore a copy using RestoreObject (https://docs.aws.amazon.com/AmazonS3/latest/API/API_RestoreObject.html) // . Otherwise, this action returns an InvalidObjectState error. For information // about restoring archived objects, see Restoring Archived Objects (https://docs.aws.amazon.com/AmazonS3/latest/dev/restoring-objects.html) // . Encryption request headers, like x-amz-server-side-encryption , should not be // sent for GET requests if your object uses server-side encryption with KMS keys // (SSE-KMS) or server-side encryption with Amazon S3–managed encryption keys // (SSE-S3). If your object does use these types of keys, you’ll get an HTTP 400 // BadRequest error. If you encrypt an object by using server-side encryption with // customer-provided encryption keys (SSE-C) when you store the object in Amazon // S3, then when you GET the object, you must use the following headers: // - x-amz-server-side-encryption-customer-algorithm // - x-amz-server-side-encryption-customer-key // - x-amz-server-side-encryption-customer-key-MD5 // // For more information about SSE-C, see Server-Side Encryption (Using // Customer-Provided Encryption Keys) (https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerSideEncryptionCustomerKeys.html) // . Assuming you have the relevant permission to read object tags, the response // also returns the x-amz-tagging-count header that provides the count of number // of tags associated with the object. You can use GetObjectTagging (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectTagging.html) // to retrieve the tag set associated with an object. Permissions You need the // relevant read object (or version) permission for this operation. For more // information, see Specifying Permissions in a Policy (https://docs.aws.amazon.com/AmazonS3/latest/dev/using-with-s3-actions.html) // . If the object you request does not exist, the error Amazon S3 returns depends // on whether you also have the s3:ListBucket permission. // - If you have the s3:ListBucket permission on the bucket, Amazon S3 will // return an HTTP status code 404 ("no such key") error. // - If you don’t have the s3:ListBucket permission, Amazon S3 will return an // HTTP status code 403 ("access denied") error. // // Versioning By default, the GET action returns the current version of an object. // To return a different version, use the versionId subresource. // - If you supply a versionId , you need the s3:GetObjectVersion permission to // access a specific version of an object. If you request a specific version, you // do not need to have the s3:GetObject permission. If you request the current // version without a specific version ID, only s3:GetObject permission is // required. s3:GetObjectVersion permission won't be required. // - If the current version of the object is a delete marker, Amazon S3 behaves // as if the object was deleted and includes x-amz-delete-marker: true in the // response. // // For more information about versioning, see PutBucketVersioning (https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketVersioning.html) // . Overriding Response Header Values There are times when you want to override // certain response header values in a GET response. For example, you might // override the Content-Disposition response header value in your GET request. You // can override values for a set of response headers using the following query // parameters. These response header values are sent only on a successful request, // that is, when status code 200 OK is returned. The set of headers you can // override using these parameters is a subset of the headers that Amazon S3 // accepts when you create an object. The response headers that you can override // for the GET response are Content-Type , Content-Language , Expires , // Cache-Control , Content-Disposition , and Content-Encoding . To override these // header values in the GET response, you use the following request parameters. You // must sign the request, either using an Authorization header or a presigned URL, // when using these parameters. They cannot be used with an unsigned (anonymous) // request. // - response-content-type // - response-content-language // - response-expires // - response-cache-control // - response-content-disposition // - response-content-encoding // // Overriding Response Header Values If both of the If-Match and // If-Unmodified-Since headers are present in the request as follows: If-Match // condition evaluates to true , and; If-Unmodified-Since condition evaluates to // false ; then, S3 returns 200 OK and the data requested. If both of the // If-None-Match and If-Modified-Since headers are present in the request as // follows: If-None-Match condition evaluates to false , and; If-Modified-Since // condition evaluates to true ; then, S3 returns 304 Not Modified response code. // For more information about conditional requests, see RFC 7232 (https://tools.ietf.org/html/rfc7232) // . The following operations are related to GetObject : // - ListBuckets (https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBuckets.html) // - GetObjectAcl (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectAcl.html) func(c *Client) GetObject(ctx context.Context, params *GetObjectInput, optFns ...func(*Options)) (*GetObjectOutput, error) { if params == nil { params = &GetObjectInput{} }
// Indicates that a range of bytes was specified. AcceptRanges *string
// Object data. Body io.ReadCloser
// Indicates whether the object uses an S3 Bucket Key for server-side encryption // with Amazon Web Services KMS (SSE-KMS). BucketKeyEnabled bool
// Specifies caching behavior along the request/reply chain. CacheControl *string
// The base64-encoded, 32-bit CRC32 checksum of the object. This will only be // present if it was uploaded with the object. With multipart uploads, this may not // be a checksum value of the object. For more information about how checksums are // calculated with multipart uploads, see Checking object integrity (https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums) // in the Amazon S3 User Guide. ChecksumCRC32 *string
// The base64-encoded, 32-bit CRC32C checksum of the object. This will only be // present if it was uploaded with the object. With multipart uploads, this may not // be a checksum value of the object. For more information about how checksums are // calculated with multipart uploads, see Checking object integrity (https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums) // in the Amazon S3 User Guide. ChecksumCRC32C *string
// The base64-encoded, 160-bit SHA-1 digest of the object. This will only be // present if it was uploaded with the object. With multipart uploads, this may not // be a checksum value of the object. For more information about how checksums are // calculated with multipart uploads, see Checking object integrity (https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums) // in the Amazon S3 User Guide. ChecksumSHA1 *string
// The base64-encoded, 256-bit SHA-256 digest of the object. This will only be // present if it was uploaded with the object. With multipart uploads, this may not // be a checksum value of the object. For more information about how checksums are // calculated with multipart uploads, see Checking object integrity (https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums) // in the Amazon S3 User Guide. ChecksumSHA256 *string
// Specifies presentational information for the object. ContentDisposition *string
// Specifies what content encodings have been applied to the object and thus what // decoding mechanisms must be applied to obtain the media-type referenced by the // Content-Type header field. ContentEncoding *string
// The language the content is in. ContentLanguage *string
// Size of the body in bytes. ContentLength int64
// The portion of the object returned in the response. ContentRange *string
// A standard MIME type describing the format of the object data. ContentType *string
// Specifies whether the object retrieved was (true) or was not (false) a Delete // Marker. If false, this response header does not appear in the response. DeleteMarker bool
// An entity tag (ETag) is an opaque identifier assigned by a web server to a // specific version of a resource found at a URL. ETag *string
// If the object expiration is configured (see PUT Bucket lifecycle), the response // includes this header. It includes the expiry-date and rule-id key-value pairs // providing object expiration information. The value of the rule-id is // URL-encoded. Expiration *string
// The date and time at which the object is no longer cacheable. Expires *time.Time
// Creation date of the object. LastModified *time.Time
// A map of metadata to store with the object in S3. // // Map keys will be normalized to lower-case. Metadata map[string]string
// This is set to the number of metadata entries not returned in x-amz-meta // headers. This can happen if you create metadata using an API like SOAP that // supports more flexible metadata than the REST API. For example, using SOAP, you // can create metadata whose values are not legal HTTP headers. MissingMeta int32
// Indicates whether this object has an active legal hold. This field is only // returned if you have permission to view an object's legal hold status. ObjectLockLegalHoldStatus types.ObjectLockLegalHoldStatus
// The Object Lock mode currently in place for this object. ObjectLockMode types.ObjectLockMode
// The date and time when this object's Object Lock will expire. ObjectLockRetainUntilDate *time.Time
// The count of parts this object has. This value is only returned if you specify // partNumber in your request and the object was uploaded as a multipart upload. PartsCount int32
// Amazon S3 can return this if your request involves a bucket that is either a // source or destination in a replication rule. ReplicationStatus types.ReplicationStatus
// If present, indicates that the requester was successfully charged for the // request. RequestCharged types.RequestCharged
// Provides information about object restoration action and expiration time of the // restored object copy. Restore *string
// If server-side encryption with a customer-provided encryption key was // requested, the response will include this header confirming the encryption // algorithm used. SSECustomerAlgorithm *string
// If server-side encryption with a customer-provided encryption key was // requested, the response will include this header to provide round-trip message // integrity verification of the customer-provided encryption key. SSECustomerKeyMD5 *string
// If present, specifies the ID of the Amazon Web Services Key Management Service // (Amazon Web Services KMS) symmetric encryption customer managed key that was // used for the object. SSEKMSKeyId *string
// The server-side encryption algorithm used when storing this object in Amazon S3 // (for example, AES256, aws:kms ). ServerSideEncryption types.ServerSideEncryption
// Provides storage class information of the object. Amazon S3 returns this header // for all objects except for S3 Standard storage class objects. StorageClass types.StorageClass
// The number of tags, if any, on the object. TagCount int32
// Version of the object. VersionId *string
// If the bucket is configured as a website, redirects requests for this object to // another object in the same bucket or to an external URL. Amazon S3 stores the // value of this header in the object metadata. WebsiteRedirectLocation *string
// Metadata pertaining to the operation's result. ResultMetadata middleware.Metadata
// PutObjectRequest generates a "aws/request.Request" representing the // client's request for the PutObject operation. The "output" return // value will be populated with the request's response once the request completes // successfully. // // Use "Send" method on the returned Request to send the API call to the service. // the "output" return value is not valid until after Send returns without error. // // See PutObject for more information on using the PutObject // API call, and error handling. // // This method is useful when you want to inject custom logic or configuration // into the SDK's request lifecycle. Such as custom headers, or retry logic. // // // // Example sending a request using the PutObjectRequest method. // req, resp := client.PutObjectRequest(params) // // err := req.Send() // if err == nil { // resp is now filled // fmt.Println(resp) // } // // See also, https://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/PutObject func(c *S3) PutObjectRequest(input *PutObjectInput) (req *request.Request, output *PutObjectOutput) { op := &request.Operation{ Name: opPutObject, HTTPMethod: "PUT", HTTPPath: "/{Bucket}/{Key+}", }
// PresignRequest behaves just like presign, with the addition of returning a // set of headers that were signed. The expire parameter is only used for // presigned Amazon S3 API requests. All other AWS services will use a fixed // expiration time of 15 minutes. // // It is invalid to create a presigned URL with a expire duration 0 or less. An // error is returned if expire duration is 0 or less. // // Returns the URL string for the API operation with signature in the query string, // and the HTTP headers that were included in the signature. These headers must // be included in any HTTP request made with the presigned URL. // // To prevent hoisting any headers to the query string set NotHoist to true on // this Request value prior to calling PresignRequest. func(r *Request) PresignRequest(expire time.Duration) (string, http.Header, error) { r = r.copy() return getPresignedURL(r, expire) }
// GetObjectRequest generates a "aws/request.Request" representing the // client's request for the GetObject operation. The "output" return // value will be populated with the request's response once the request completes // successfully. // // Use "Send" method on the returned Request to send the API call to the service. // the "output" return value is not valid until after Send returns without error. // // See GetObject for more information on using the GetObject // API call, and error handling. // // This method is useful when you want to inject custom logic or configuration // into the SDK's request lifecycle. Such as custom headers, or retry logic. // // // // Example sending a request using the GetObjectRequest method. // req, resp := client.GetObjectRequest(params) // // err := req.Send() // if err == nil { // resp is now filled // fmt.Println(resp) // } // // See also, https://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/GetObject func(c *S3) GetObjectRequest(input *GetObjectInput) (req *request.Request, output *GetObjectOutput) { op := &request.Operation{ Name: opGetObject, HTTPMethod: "GET", HTTPPath: "/{Bucket}/{Key+}", }
当客户端发送一个 HTTP 请求时,可以在请求头中包含 Range 字段来指定所需的资源范围。该字段的格式为 bytes=start-end,其中 start 和 end 分别表示资源的起始字节和结束字节的索引。服务器在接收到带有 Range 请求头的请求后,会返回指定范围的资源内容,并在响应头中包含 Content-Range 字段来指示返回内容的范围,而且返回的HTTP Code是206。