Deleting an Object
Functions
If an object is no longer used or does not need to be stored, you can delete it in a timely manner to reduce memory usage and storage costs. For more information about deleting an object, see Deleting an Object. If the object to be deleted is not found, a success message is still returned.
Working with Other Functions
When versioning is enabled for a bucket, a delete request that does not specify a version ID cannot permanently delete the object. Instead, OBS creates a delete marker with a unique version ID. When versioning is suspended for a bucket, a delete request that does not specify a version ID deletes the object whose version ID is null and creates a delete marker with a version ID of null.
To delete an object of a specified version, the versionId parameter can be used to specify the desired version.
OBS automatically enables versioning when you enable WORM for a bucket. If you delete an object without specifying a version ID, OBS does not really delete this object thanks to versioning, but inserts a delete marker with a unique version ID, which turns into the current version. If you specify a version ID when deleting an object protected by WORM, OBS prevents you from deleting this object and returns a 403 error. Delete markers are not protected by WORM.
Authorization Information
To call this API, you must be the object owner or have the permissions to delete an object. You are advised to use IAM or bucket policies for authorization. For details about OBS authorization methods, see Differences Between OBS Permissions Control Methods.
- If you use IAM for authorization, you need to use either role/policy-based authorization or identity policy-based authorization and configure the required permissions:
- If you use role/policy-based authorization (IAM v3 APIs in the old IAM version), you need to grant the obs:object:DeleteObject (versioning disabled) and obs:object:DeleteObjectVersion (versioning enabled or suspended) permissions. For details, see Creating a Custom IAM Policy.
- If you use identity policy-based authorization (IAM v5 APIs in the new IAM version), you need to grant the obs:object:deleteObject (versioning disabled) and obs:object:deleteObjectVersion (versioning enabled or suspended) permissions, as shown in the following table. For details, see Creating a Custom IAM Identity Policy.
Action
Access Level
Resource Type (*: Required)
Dependencies
obs:object:deleteObject (versioning disabled)
obs:object:deleteObjectVersion (versioning enabled or suspended)
Write
object *
-
- functiongraph:function:invokeAsync
- functiongraph:workflow:invoke
- smn:topic:publish
-
- obs:EpochTime
- obs:SourceIp
- obs:TlsVersion
- obs:CustomDomain
- If you use bucket policies for authorization, you need to grant the obs:object:DeleteObject (versioning disabled) and obs:object:DeleteObjectVersion (versioning enabled or suspended) permissions. For details, see Creating a Custom Bucket Policy.
Request Syntax
1 2 3 4 |
DELETE /ObjectName HTTP/1.1 Host: bucketname.obs.region.myhuaweicloud.com Date: date Authorization: authorization |
URI Parameters
Table 1 describes the request parameters.
For deleting an object, only parameters listed in Table 1 are supported. If the request contains parameters that cannot be identified by OBS, the server returns the 400 error code.
Request Headers
This request uses common headers. For details, see Table 3.
Request Body
This request contains no request body parameters.
Response Syntax
1 2 |
HTTP/1.1 status_code Date: date |
Status Codes
For details about the status codes, see Status Codes.
If the object to be deleted is not found, a success message is still returned.
Response Headers
This response uses common headers. For details, see Table 1.
If versioning is enabled for the bucket, the headers listed in Table 2 may also be used.
|
Header |
Description |
|---|---|
|
x-obs-delete-marker |
Definition: Whether an object has a delete marker. If the object is not marked as deleted, the response does not contain this header. Type: boolean Constraints: None Range:
Default value: false |
|
x-obs-version-id |
Definition: Object version ID. If the object has no version number specified, the response does not contain this header. Type: string Constraints: None Range: The value must contain 32 characters. Default value: None |
Response Body
This response contains no elements.
Error Responses
No special error responses are returned. For details about error responses, see Table 2.
Sample Request
1 2 3 4 5 6 |
DELETE /object2 HTTP/1.1 User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Accept: */* Date: WED, 01 Jul 2015 04:19:21 GMT Authorization: OBS H4IPJX0TQTHTHEBQQCEC:MfK9JCnSFHCrJmjv7iRkRrrce2s= |
Sample Response
1 2 3 4 5 |
HTTP/1.1 204 No Content Server: OBS x-obs-request-id: 8DF400000163D3F51DEA05AC9CA066F1 x-obs-id-2: 32AAAUgAIAABAAAQAAEAABAAAQAAEAABCSgkM4Dij80gAeFY8pAZIwx72QhDeBZ5 Date: WED, 01 Jul 2015 04:19:21 GMT |
Sample Request: Specifying versionId to Delete a Specific Object Version
DELETE /object2?versionId=G001118A49821905FFFFD28739D419DA HTTP/1.1 Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4= User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Date: WED, 01 Jul 2015 02:37:22 GMT Content-Type: application/xml
Sample Response: Specifying versionId to Delete a Specific Object Version
x-obs-id-2: 32AAAUgAIAABAAAQAAEAABAAAQAAEAABCS3WJqDiMsxgGHKQrlqST9veFKpDgE50 x-obs-request-id: 0000018A4997390DD306CCDA0DEC814F Server: OBS Date: WED, 01 Jul 2015 02:37:22 GMT x-obs-version-id: G001118A49821905FFFFD28739D419DA
Sample Request: Specifying versionId to Delete a Delete Marker
DELETE /object2?versionId=G001118A6456208AFFFFD24829FCF614 Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4= User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Date: WED, 01 Jul 2015 02:37:22 GMT Content-Type: application/xml
Sample Response: Specifying versionId to Delete a Delete Marker
x-obs-id-2: 32AAAUgAIAABAAAQAAEAABAAAQAAEAABCS3WJqDiMsxgGHKQrlqST9veFKpDgE50 x-obs-request-id: 0000018A4997390DD306CCDA0DEC814F Server: OBS Date: WED, 01 Jul 2015 02:37:22 GMT x-obs-version-id: G001118A6456208AFFFFD24829FCF614
Using SDKs to Call APIs
You are advised to use OBS SDKs to call APIs. SDKs encapsulate APIs to simplify development. You can call SDK API functions to access OBS without manually calculating signatures.
Helpful Links
- To use obsutil to delete objects, see Deleting an Object.
- To use OBS Browser+ to delete objects, see Deleting a File or Folder.
- For more information about deleting objects, see Deleting an Object.
- For details about the billing items involved in API operations, see Billing Items.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot