This topic describes how to delete a single object or multiple objects using OSS SDK for Go.
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 an internal endpoint. For more information about the regions and endpoints supported by Object Storage Service (OSS), see OSS regions and endpoints.In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
The
oss:DeleteObject
permission is required to delete an object. For more information, see Grant custom permissions to RAM users.
Methods
Delete a single object
func (c *Client) DeleteObject(ctx context.Context, request *DeleteObjectRequest, optFns ...func(*Options)) (*DeleteObjectResult, error)
Delete multiple objects
func (c *Client) DeleteMultipleObjects(ctx context.Context, request *DeleteMultipleObjectsRequest, optFns ...func(*Options)) (*DeleteMultipleObjectsResult, 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 | *DeleteObjectRequest | Parameters of an API operation, such as the name of the object. For more information, visit DeleteObjectRequest. |
*DeleteMultipleObjectsRequest | Parameters of an API operation, such as the list of objects to delete. For more information, visit DeleteMultipleObjectsRequest. | |
optFns | ...func(*Options) | Optional. The operation-level parameters. For more information, see Options. |
Response parameters
Parameter | Type | Description |
result | *DeleteObjectResult | The response to the operation. This parameter is valid when the value of err is nil. For more information, visit DeleteObjectResult. |
*DeleteMultipleObjectsResult | The response to the operation. This parameter is valid when the value of err is nil. For more information, visit DeleteMultipleObjectsResult. | |
err | error | The status of the request. If the request fails, the value of err is not nil. |
Sample code
References
For more information about the complete sample code that is used to delete objects, visit delete_object.go and delete_mutiple_objects.go.
For more information about the API operation that you can call to delete a single object, see DeleteObject.
For more information about the API operation that you can call to delete multiple objects, see DeleteMultipleObjects.