Description
The Delete Object API is used to delete a file (object) in a COS bucket. This operation requires the requester to have the write permission on the bucket.
Notes
- In a Delete Object request, deleting a non-existing object is still considered successful, and it returns
204 No Content. - Delete Object requires the user to have write permissions for that object.
Versioning
To delete a specific version of an object (including the delete marker, same as below), use the versionId parameter to specify the version ID (including the version ID of the delete marker, same as below). In this case, the response includes the x-cos-version-id response header, representing the version ID deleted by this request.
If the versionId parameter is not specified.
- When versioning is enabled, the DELETE operation creates a delete marker as the latest version of the specified object. The response returns the x-cos-version-id response header, representing the version ID of the delete marker created by this request.
- When versioning is suspended, the DELETE operation creates a delete marker whose version ID is null as the latest version of the specified object and deletes any existing versions with a null version ID (if any).
When the DELETE operation creates or deletes a delete marker, the x-cos-delete-marker: true response header is returned, indicating that the DELETE operation has created or deleted the delete marker of the specified object.
For details about the status (enabled/suspended) of versioning, see Version Control Overview.
Request
Syntax example:
DELETE /ObjectName HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Date: GMT Date
Content-Length: length
Authorization: Auth String
Note:
Authorization: Auth String (See Request Signature for details.)
Request Line
DELETE /ObjectName HTTP/1.1
This API accepts DELETE requests.
Request Parameters
| Name | Description | Type | Required |
|---|---|---|---|
| versionId | Version ID to be deleted. | string | No |
Request Header
Common Headers
This request uses common request headers. For details, see Common Request Headers.
Non-common Headers
This request has no special request header information.
Request Body
The request body for this request is empty.
Response
Response Headers
Common Response Headers
This response uses common response headers. For details, see Public Response Header.
Special Response Headers
There are no special response headers for this request operation.
Versioning-related headers
The following table describes response headers returned when you delete an object or a specified object version from a versioning-enabled bucket.
| Name | Description | Type |
|---|---|---|
| x-cos-version-id | Version ID of the object or delete marker. | string |
| x-cos-delete-marker | - When the versionId parameter is used to specify the version ID of a delete marker, this response header is returned with a value of true, indicating that the version ID of a delete marker is deleted. - When the versionId parameter is not used, and versioning is enabled for the bucket where the specified object is located, this response header is returned with a value of true, indicating that a delete marker is created as the latest version of the object. |
boolean |
Response Body
The response body of this request is empty.
Error Analysis
The following describes some special but common errors that may occur with this request:
| Error Code | HTTP Status Code | Description |
|---|---|---|
| NoSuchBucket | 404 Not Found | The bucket does not exist. |
For details on COS error codes or a complete list of product error codes, see Error Codes.
Practical Case
Request
DELETE /123 HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Date: Wed, 23 Oct 2016 21:32:00 GMT
Authorization: q-sign-algorithm=sha1&q-ak=AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&q-sign-time=1484213409;32557109409&q-key-time=1484213409;32557109409&q-header-list=host&q-url-param-list=&q-signature=1c24fe260ffe79b8603f932c4e916a6cbb0af44a
Response
HTTP/1.1 204 No Content
Content-Type: application/xml
Content-Length: 0
Connection: keep-alive
Date: Wed, 23 Oct 2016 21:32:00 GMT
x-cos-request-id: NTg3NzRjYTRfYmRjMzVfMzFhOF82MmM3Yg==