You can call the DeleteObject operation to delete an object.

Usage notes

When you call the DeleteObject operation, take note of the following items:

  • You must have the write permission on the object to be deleted.
  • HTTP status code 204 is returned when the DeleteObject operation succeeds, regardless of whether the object exists.
  • If the requested object is a symbolic link, the DeleteObject operation deletes only the symbolic link but not the content that the link directs to.

Versioning

If you do not specify the version ID when performing the DeleteObject operation on an object in a versioning-enabled bucket, the current version of the object is retained. A delete marker is added and becomes the current version of the object. If you specify the version ID, the object with the specified version ID is permanently deleted.

  • If you do not specify the version ID:

    By default, the DeleteObject operation is performed on the current version of the target object. The current version is retained and a delete marker is inserted as the new current version of the object. When the GetObject operation is performed on the object, and OSS identifies that the current version of the object is a delete marker. OSS returns 404 Not Found. Additionally, the x-oss-delete-marker = true and x-oss-version-id headers are included in the response. x-oss-version-id indicates the version ID of the delete marker.

    If the value of the x-oss-delete-marker field is true, the version specified in the x-oss-version-id field is a delete marker.

  • If you specify the version ID when you perform the DeleteObject operation:

    OSS permanently deletes the object version specified by the versionid parameter. For example, to delete an object whose version ID is null, you must specify the value of versionId in the request as null. OSS identifies the string null as a version ID and deletes the object whose version ID is null.

Response headers

Header Type Description
x-oss-delete-marker bool
  • If you do not specify the object version ID when you perform the DeleteObject operation, OSS creates a delete marker as the current version and includes this header with the "true" value in the response.
  • If you specify the object version ID to permanently delete a version of the target object and the specified version is a delete marker, OSS includes this header with the "true" value in the response.
Valid value: true
x-oss-version-id String
  • If you do not specify the object version ID when you perform the DeleteObject operation, OSS creates a delete marker as the current version and includes this header in the response to indicate the version ID of the created delete marker.
  • If you specify the object version ID to permanently delete a version of the target object, OSS includes this header in the response to indicate the ID of the deleted object version.

Request syntax

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

Examples

  • Sample requests
    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: */*
    Connection: keep-alive
    date: Wed, 02 Jan 2019 13:28:38 GMT
    authorization: OSS qn6qrrqxo2oawuk53otfjbyc:zUglwRPGkbByZxm1+y4eyu+NIUs=zV0****
    Content-Length: 0
    Sample responses
    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
  • Sample request when the object version ID is not specified
    In this case, OSS inserts a delete marker. The x-oss-delete-marker=true field is included in the response.
    DELETE /example HTTP/1.1
    Host: versioning-delete.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 09 Apr 2019 04:08:23 GMT
    Authorization: OSS twnetzwjkqr9eq6:z73SSKA6t2tNTP4GuPjPiyV/****
    Sample responses
    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
  • Sample request when the object version ID is specified
    In this case, the object with the specified version ID is permanently deleted.
    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: OSS gb3m2qiwirupd6v:UjOXBmIbJD3qXL+DP1EDNyCI****
    Sample responses
    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
  • Sample request when the object version ID is specified to delete a delete marker
    Note You can delete only a delete marker.

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

    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: OSS jh475i54ffozhoy:4tX6Z+fnhtINhp0g+sRiLEQb****
    Sample responses
    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

The SDKs of the DeleteObject operation for various programming languages:

Error codes

Error code HTTP status code Description
FileImmutable 409 The error message returned because you delete or modify the data. During the protection period, data in the bucket is protected.