Delete objects (Go SDK V2)
Use the OSS SDK for Go to delete one or more objects from a bucket.
Notes
-
The sample code uses the
cn-hangzhouregion ID for China (Hangzhou) and a public endpoint by default. To access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about supported regions and endpoints, see Regions and endpoints. -
The examples obtain access credentials from environment variables. For more information, see Configure access credentials.
-
To delete an object, you must have the
oss:DeleteObjectpermission. For more information, see Grant custom permission policies to RAM users.
Method signatures
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 request context, which you can use to set a request timeout. |
|
request |
*DeleteObjectRequest |
The request parameters, such as the object name. For more information, see DeleteObjectRequest. |
|
*DeleteMultipleObjectsRequest |
The request parameters, such as the list of objects to delete. For more information, see DeleteMultipleObjectsRequest. |
|
|
optFns |
...func(*Options) |
(Optional) Operation-level configuration parameters. For more information, see Options. |
Response parameters
|
Parameter |
Type |
Description |
|
result |
*DeleteObjectResult |
The operation result. Valid only when |
|
*DeleteMultipleObjectsResult |
The operation result. Valid only when |
|
|
err |
error |
The request status. If the request fails, |
Examples
References
-
For complete sample code, see delete_object.go and delete_multiple_objects.go on GitHub.
-
For the API reference for deleting a single object, see DeleteObject.
-
For the API reference for deleting multiple objects, see DeleteMultipleObjects.