Delete a single object or multiple objects from a bucket using OSS SDK for Go.
Prerequisites
The sample code uses the
cn-hangzhouregion ID (China (Hangzhou) region). A public endpoint accesses bucket resources by default. To access the bucket from other Alibaba Cloud services in the same region, use an internal endpoint. See OSS regions and endpoints.Access credentials come from environment variables. See Configure access credentials.
Deleting objects requires the
oss:DeleteObjectpermission. 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 | Request context. Specifies the total request duration. |
request | Parameters for the DeleteObject operation. | |
Parameters for the DeleteMultipleObjects operation. | ||
optFns | ...func(*Options) | Optional. Operation-level parameters. |
Response parameters
Parameter | Type | Description |
result | Response to the DeleteObject operation. Valid when err is nil. | |
Response to the DeleteMultipleObjects operation. Valid when err is nil. | ||
err | error | Request status. Non-nil if the request fails. |
Examples
References
Complete sample code: delete_object.go | delete_mutiple_objects.go
API reference: DeleteObject | DeleteMultipleObjects