This topic describes how to use the OSS SDK for Python to delete a single file or multiple files.
Precautions
The sample code in this topic uses the China (Hangzhou) region ID
cn-hangzhouand a public endpoint by default. If you want to access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about the mappings between OSS regions and endpoints, see Regions and endpoints.To delete a file, you must have the
oss:DeleteObjectpermission. For more information, see Grant custom permissions to a RAM user.
Method definitions
Delete a single file
delete_object(request: DeleteObjectRequest, **kwargs) → DeleteObjectResultDelete multiple files
delete_multiple_objects(request: DeleteMultipleObjectsRequest, **kwargs) → DeleteMultipleObjectsResultRequest parameters
Parameter | Type | Description |
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 |
Return values
Type | Description |
DeleteObjectResult | The return value. For more information, see DeleteObjectResult |
DeleteMultipleObjectsResult | The return value. For more information, see DeleteMultipleObjectsResult |
For the complete definition of the method for deleting a single file, see delete_object.
For the complete definition of the method for deleting multiple files, see delete_multiple_objects.
Sample code
References
For the complete sample code for deleting a single file, see delete_object.py.
For the complete sample code for deleting multiple files, see delete_multiple_objects.py.