Enable pay-by-requester using OSS SDK for Go 2.0
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. This is useful for sharing data without incurring additional request and traffic fees.
Usage notes
-
The sample code in this topic uses the region ID
cn-hangzhouof the China (Hangzhou) region and the public endpoint. To access OSS from other Alibaba Cloud services in the same region, 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, see Configure access credentials.
-
To enable pay-by-requester, you must have the
oss:PutBucketRequestPaymentpermission. To query the pay-by-requester configurations, you must have theoss:GetBucketRequestPaymentpermission. 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 request context, which can be used to specify the total duration of the request. |
|
request |
*PutBucketRequestPaymentRequest |
The request parameters. For more information, see PutBucketRequestPaymentRequest. |
|
*GetBucketRequestPaymentRequest |
The request parameters. For more information, see GetBucketRequestPaymentRequest. |
|
|
optFns |
...func(*Options) |
Optional. Operation-level parameters. For more information, see Options. |
Response parameters
|
Response parameter |
Type |
Description |
|
result |
*PutBucketRequestPaymentResult |
The response. Valid when err is nil. For more information, see PutBucketRequestPaymentResult. |
|
*GetBucketRequestPaymentResult |
The response. Valid when err is nil. For more information, see GetBucketRequestPaymentResult. |
|
|
err |
error |
The error message. A non-nil value indicates that the request failed. |
Examples
References
-
For the complete sample code for enabling pay-by-requester, visit GitHub.
-
For the API reference for enabling pay-by-requester, visit PutBucketRequestPayment.
-
For the complete sample code for querying the pay-by-requester configurations of a bucket, visit GitHub.
-
For the API reference for querying pay-by-requester configurations, visit GetBucketRequestPayment.