When pay-by-requester is enabled for a bucket, the requester pays the request and traffic fees, and the bucket owner pays only the storage costs. You can enable pay-by-requester for a bucket to share data in the bucket without paying for the request and traffic fees when your bucket is accessed.
Usage notes
The sample code in this topic uses the region ID
cn-hangzhou
of the China (Hangzhou) region. By default, the public endpoint is used to access resources in a bucket. If you want to access resources in the bucket by using other Alibaba Cloud services in the same region in which the bucket is located, use the internal endpoint. For more information about OSS regions and endpoints, see Regions and endpoints.In this topic, access credentials are obtained from environment variables. For more information about how to configure the access credentials, see Configure access credentials.
To enable pay-by-requester, you must have the
oss:PutBucketRequestPayment
permission. To query the pay-by-requester configurations, you must have theoss:GetBucketRequestPayment
permission. For more information, see Common examples of RAM policies.
Method
Enable pay-by-requester for a bucket
func (c *Client) PutBucketRequestPayment(ctx context.Context, request *PutBucketRequestPaymentRequest, optFns ...func(*Options)) (*PutBucketRequestPaymentResult, error)
Query the pay-by-requester configurations of a bucket
func (c *Client) GetBucketRequestPayment(ctx context.Context, request *GetBucketRequestPaymentRequest, optFns ...func(*Options)) (*GetBucketRequestPaymentResult, error)
Request parameters
Parameter | Type | Description |
ctx | context.Context | The context of the request, which can be used to specify the total duration of the request. |
request | *PutBucketRequestPaymentRequest | Specifies the parameters of a specific API operation. For more information, see PutBucketRequestPaymentRequest. |
*GetBucketRequestPaymentRequest | Specifies the parameters of a specific API operation. For more information, see GetBucketRequestPaymentRequest. | |
optFns | ...func(*Options) | Optional. The operation-level parameter. For more information, see Options. |
Response parameters
Response parameter | Type | Description |
result | *PutBucketRequestPaymentResult | The response to the operation. This parameter is valid when the value of err is nil. For more information, see PutBucketRequestPaymentResult. |
*GetBucketRequestPaymentResult | The response to the operation. This parameter is valid when the value of err is nil. For more information, see GetBucketRequestPaymentResult. | |
err | error | The status of the request. If the request fails, the value of err cannot be nil. |
Examples
References
For the complete sample code that is used to enable pay-by-requester, visit GitHub.
For more information about the API operation that you can call to enable pay-by-requester, visit PutBucketRequestPayment.
For the complete sample code that is used to query the pay-by-requester configurations of a bucket, visit GitHub.
For more information about the API operation that you can call to query the pay-by-requester configurations of a bucket, visit GetBucketRequestPayment.