Updated on 2026-03-06 GMT+08:00

Truncating an Object

Functions

This operation can truncate an object to a specified size.

This API is supported only by parallel file systems. For details about how to create a parallel file system, see Sample Request: Creating a Parallel File System.

Authorization Information

To call this API, you must be the object owner or have the permission to truncate 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:PutObject permission. 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:putObject permission, as shown in the following table. For details, see Creating a Custom IAM Identity Policy.

      Action

      Access Level

      Resource Type (*: Required)

      Condition Key

      Alias

      Dependencies

      obs:object:putObject

      Permission_management

      object *

      g:EnterpriseProjectId

      -

      -

      -

      • obs:EpochTime
      • obs:SourceIp
      • obs:TlsVersion
      • obs:CustomDomain
      • obs:x-obs-acl
  • If you use bucket policies for authorization, you need to grant the obs:object:putObject permission. For details, see Creating a Custom Bucket Policy.

Request Syntax

PUT /ObjectName?truncate&length=Length HTTP/1.1
Host: bucketname.obs.region.myhuaweicloud.com 
Authorization: authorization
Content-Length: length
Date: date

Request Parameters

The request needs to specify parameters in the message, indicating that this is to truncate an object to a specified size. Table 1 describes the parameters.

Table 1 Request parameters

Parameter

Mandatory (Yes/No)

Type

Description

truncate

Yes

String

Definition:

If this parameter is carried, the request uploads data by truncating the object.

Constraints:

None

Range:

None

Default value:

None

length

Yes

Integer

Definition:

Size of the object after the truncation Unit: byte.

Constraints:

None

Range:

0 to 54975581388800 (50 TB)

Default value:

None

Request headers

This request uses common request headers. For details, see Table 3.

Request Elements

This request involves no elements.

Response Syntax

1
2
3
4
5
HTTP/1.1 204 status_code
Server: OBS
x-obs-request-id: request-id
x-obs-id-2: id
Date: Date

Response Headers

The response to the request uses common headers. For details, see Table 1.

Response Elements

This response contains no elements.

Error Responses

No special error responses are returned. For details about error responses, see Table 2.

Sample Request

PUT /ObjectName?truncate&length=1000 HTTP/1.1
Host: examplebucket.obs.region.myhuaweicloud.com
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:75/Y4Ng1izvzc1nTGxpMXTE6ynw=
Content-Length: 1
Date: WED, 01 Jul 2015 04:19:20 GMT

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