DeleteObject

更新时间:
复制 MD 格式

Deletes an object.

Usage notes

  • If a bucket has data replication rules configured and set to synchronize all changes to data (Add/Delete/Change), including creation, modification, and deletion of objects, calling the DeleteObject operation to delete objects stored within will result in the replicated objects being deleted from the destination bucket associated with the replication policy. Moreover, if versioning is also enabled for this bucket, delete markers will be created for deleted objects in the source bucket and replicated to the destination bucket when you call the DeleteObject operation.

  • Deleted objects cannot be recovered. Proceed with caution. For more information about how to delete objects, see Delete objects.

  • HTTP 204 status code is returned when the DeleteObject operation succeeds, regardless of whether the object exists.

  • If the object you want to delete is a symbolic link, the DeleteObject operation deletes only the symbolic link but not the object to which the link points.

Versioning

When you call DeleteObject to delete an object from a versioned bucket, you must determine whether to specify a version ID in the request.

  • Delete an object without specifying a version ID (temporary deletion)

    If you do not specify the version ID of the object that you want to delete in the request, OSS does not delete the current version of the object but adds a delete marker to the object as the new version. In addition, the response to the request includes the x-oss-delete-marker = true header and the x-oss-version-id header that indicates the version ID of the created delete marker.

    If the value of x-oss-delete-marker is true, the value of x-oss-version-id is the version ID of the delete marker.

    Note

    If you delete an object without specifying its version ID in a versioning-suspended bucket and the object already has a null version, OSS adds a delete maker with a version ID of null to overwrite the existing null version. An object can have up to one version whose version ID is null.

  • Delete an object by specifying a version ID (permanent deletion)

    If you specify versionId in params of the request, OSS deletes the specified version. If you want to delete a null version, include params['versionId'] = "null" in params. OSS identifies the string "null" as the ID of the version to delete and deletes the null version.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM policies or Bucket Policy.

API

Action

Description

DeleteObject

oss:DeleteObject

Deletes an object.

oss:DeleteObjectVersion

Deletes a specific version of an object.

Request syntax

DELETE /ObjectName HTTP/1.1
Host: BucketName.oss-cn-hangzhou.aliyuncs.com
Date: GMT Date
Authorization: SignatureValue

当您在OSS ON云盒中调用该接口时,您需要将Host替换为云盒Endpoint。更多信息,请参见云盒Endpoint

Request headers

All headers in a DescribeRegions request are common request headers. For more information, see Common request headers.

Response headers

Header

Type

Example

Description

x-oss-delete-marker

Boolean

true

Indicates whether the object is a delete marker.

  • If you do not specify the version ID of the object that you want to delete in the DeleteObject request, OSS creates a delete marker as the current version of the object and includes this header with a value of true in the response.

  • If you specify the version ID of the object you want to delete in the DeleteObject request and the specified version is a delete marker, OSS includes this header with a value of true in the response.

Valid value: true

x-oss-version-id

String

CAEQMxiBgIDh3ZCB0BYiIGE4YjIyMjExZDhhYjQxNzZiNGUyZTI4ZjljZDcz****

The version ID of the deleted object.

  • If you do not specify the version ID of the object that you want to delete in the DeleteObject request, OSS creates a delete marker as the current version of the object and includes this header in the response to indicate the version ID of the created delete marker.

  • If you specify the version ID of the object you want to delete in the DeleteObject request, OSS includes this header in the response to indicate the ID of the deleted object version.

The response to this request contains common response headers. For more information about common response headers, see Common response headers.

Examples

  • Delete an object from an unversioned bucket.

    Sample request

    DELETE /AK.txt HTTP/1.1
    Host: test.oss-cn-zhangjiakou.aliyuncs.com
    Accept-Encoding: identity
    User-Agent: aliyun-sdk-python/2.6.0(Windows/7/AMD64;3.7.0)
    Accept: text/html
    Connection: keep-alive
    Date: Wed, 02 Jan 2019 13:28:38 GMT
    authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
    Content-Length: 0

    Sample response

    HTTP/1.1 204 No Content
    Server: AliyunOSS
    Date: Wed, 02 Jan 2019 13:28:38 GMT
    Content-Length: 0
    Connection: keep-alive
    x-oss-request-id: 5C2CBC8653718B5511EF4535
    x-oss-server-time: 134
  • Delete an object from a versioned bucket without specifying a version ID.

    In this case, OSS adds a delete marker to the object and includes the x-oss-delete-marker=true header in the response.

    Sample request

    DELETE /example HTTP/1.1
    Host: versioning-delete.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 04:08:23 GMT
    Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e

    Sample response

    HTTP/1.1 204 NoContent
    x-oss-delete-marker: true
    x-oss-version-id: CAEQMxiBgIDh3ZCB0BYiIGE4YjIyMjExZDhhYjQxNzZiNGUyZTI4ZjljZDcz****
    x-oss-request-id: 5CAC1AB7B7AEADE01700****
    Date: Tue, 09 Apr 2019 04:08:23 GMT
    Connection: keep-alive
    Server: AliyunOSS
  • Delete a version of the object from a versioned bucket by specifying the version ID.

    In this case, the specified version of the object is permanently deleted.

    Sample request

    DELETE /example?versionId=CAEQOBiBgIDNlJeB0BYiIDAwYjJlNDQ4YjJkMzQxMmY5NTM5N2UzZWNiZTQ2**** HTTP/1.1
    Host: versioning-delete.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 04:11:54 GMT
    Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e

    Sample response

    HTTP/1.1 204 No Content
    x-oss-version-id: CAEQOBiBgIDNlJeB0BYiIDAwYjJlNDQ4YjJkMzQxMmY5NTM5N2UzZWNiZTQ2****
    x-oss-request-id: 5CAC1B8AB7AEADE01700****
    Date: Tue, 09 Apr 2019 04:11:54 GMT
    Content-Length: 0
    Connection: keep-alive
    Server: AliyunOSS
  • Delete a delete marker from a versioned bucket by specifying the version ID of the delete marker.

    In the following example, the specified version is a delete marker. The x-oss-delete-marker=true header is included in the response.

    Sample request

    DELETE /example?versionId=CAEQOBiBgIDNlJeB0BYiIDAwYjJlNDQ4YjJkMzQxMmY5NTM5N2UzZWNiZTQ2**** HTTP/1.1
    Host: versioning-delete.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 04:16:25 GMT
    Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e

    Sample response

    HTTP/1.1 204 No Content
    x-oss-delete-marker: true
    x-oss-version-id: CAEQNhiBgIDFtp.B0BYiIDk4NzgwMmU4NDMyOTQyM2NiMDQxOTcxYWNhMjc1****
    x-oss-request-id: 5CAC1C99B7AEADE01700****
    Date: Tue, 09 Apr 2019 04:16:25 GMT
    Content-Length: 0
    Connection: keep-alive
    Server: AliyunOSS

SDK

You can use OSS SDKs for the following programming languages to call DeleteObject:

ossutil

For information about the ossutil command that corresponds to the DeleteObject operation, see delete-object.

References

  • For information about the API operation that you can call to delete multiple objects at a time, see DeleteMultipleObjects.

  • For formation about how to automatically delete objects, see Lifecycle.

Error codes

Error code

HTTP status code

Description

FileImmutable

409

You attempt to delete or modify protected data. During the protection period, data in the bucket cannot be deleted or modified.