目录

HistoryVersions:update

Function

Updates a historical file version.

Scenario

By calling the HistoryVersions.update API, your app can update a historical file version.

Restrictions

Prototype

Protocol

HTTP PATCH

Direction

Developer server -> HUAWEI Drive server

URL

https://driveapis.cloud.huawei.com.cn/drive/v1/files/{fileId}/historyVersions/{historyVersionId}

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Path Parameters

Parameter

Mandatory/Optional

Type

Description

fileId

Mandatory

string

File ID.

historyVersionId

Mandatory

string

ID of a historical version.

Query Parameters

Parameter

Mandatory/Optional

Type

Description

fields

Mandatory

string

Fields in the request, which are in the partial response format. For details, please refer to Overview.

form

Optional

string

Media format.

prettyPrint

Optional

boolean

Indicates whether to return a response in a human-readable format.

quotaId

Optional

string

User identifier, which can contain a maximum of 40 characters. This parameter is used to restrict the maximum number of API calls for a single user.

callback

Optional

string

Callback function used in JSONP requests.

Request Parameters

Request Header

Parameter

Mandatory/Optional

Type

Description

Authorization

Mandatory

string

User authorization information, that is, the access token (AT).

x-hw-trace-id

Optional

string

ID used for service tracing.

x-hw-app-id

Optional

string

App ID.

version

Optional

string

SDK version number.

x-hw-terminal

Optional

string

Device model.

x-hw-os

Optional

string

Device operating system.

unionID

Optional

string

User's UnionID.

User-Agent

Optional

string

App version number or app ID.

x-hw-deviceUUID

Optional

string

UUID of the device.

x-hw-deviceUDID

Optional

string

UDID of the device.

x-hw-appPackageName

Optional

string

App package name.

x-hw-network

Optional

string

Network type. The options include WiFi, 2G, 3G, 4G, 5G, and wire.

Request Body

Parameter

Mandatory/Optional

Type

Description

keepPermanent

Mandatory

boolean

Indicates whether a historical version will be permanently kept.

Request Example

PATCH
https://driveapis.cloud.huawei.com.cn/drive/v1/files/BgZ_uIemYqVW0WYk0eNtKVYLMryFlmKjV/historyVersions/362238192574807808.362238192574807809?fields=* HTTP/1.1
Accept: application/json
Authorization: Bearer
CgB6e3x9Bjh6m9tm8OB0GXjeMWk0m4pVnLmwteDNWXOKPhh0/tjwtIy6Q+OscvD7zhdrElYD0Rak6xA7dI4BM3GSQTuUgFK6ZwFk7K/fjJS5vB7JFmV3
Cache-Control: no-cache
{
  "keepPermanent": false
 }

Response Parameters

When the status code is 200:

Parameter

Type

Description

category

string

Resource category. The value is always drive#historyVersion.

id

string

ID of a historical version.

mimeType

string

MIME type of the file.

editedTime

string

Last time when a historical version is modified.

keepPermanent

boolean

Indicates whether a historical version will be permanently kept.

lastEditor.category

string

User type. The value is always drive#user.

lastEditor.displayName

string

Display name of the user.

lastEditor.profilePhotoLink

string

Link to the user's profile picture, which is not returned by default.

lastEditor.me

boolean

Indicates whether the user is the requesting user.

lastEditor.permissionId

string

Permission ID.

lastEditor.userAccount

string

Account of the user, which is not returned by default.

originalFilename

string

Original file name of a historical version. This parameter specifies the file name used when the file entity is created for the first time. The value can be obtained only when the metadata involves file entity updates.

size

integer

File size.

sha256

string

SHA-256 value for the file.

Response Example

HTTP/1.1 200 OK 
{
    "editedTime": "2020-05-14T11:02:38Z",
    "size": 36,
    "sha256": "5b6e8d44920733d30740f5e59b9833e40d81674a02dbdfa2204165d4e338ac7d",
    "lastEditor": {
 "permissionId": "299639512454136576",
 "displayName": "*******3121@**3.com",
 "me": true,
 "category": "drive#user"
 },
    "id": "362238192574807808.362238192574807809",
    "originalFilename":"1.jpg"
    "mimeType": "image/jpeg",
    "category": "drive#historyVersion",
    "keepPermanent": false
}

Common Result Codes

The last four digits in the result code indicate the service error code, which is used to differentiate error scenarios. For details about other service error codes, please refer to Status Codes.

Status Code

Result Code

Response Code

Description

200

NA

  

Success.

400

21004002

PARAM_INVALID

Invalid input parameter. Check the parameter list.

403

21074033

AGREEMENT_NOT_SIGNED

The HUAWEI Drive user agreement is not signed. Try again after the agreement is signed.

403

21084031

DATA_MIGRATINT

The security policy is being updated. Please wait until the update is complete.

403

21084038

OUTER_SERVICE_ERROR

External server error.

403

21084038

OUTER_SERVICE_ERROR

The associated file is incorrect.

403

21094038

OUTER_SERVICE_ERROR

External service error.

500

21085002

OUTER_SERVICE_UNAVAILABLE

External service is unavailable.

Call Example

	public static void main(String[] args) throws IOException {
        // Set the request URL, file ID, historical version ID, and access token.
        String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/files";
        String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A";
        String historyVersionId = "367254548466646784.367254548466646785";
        String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ==";
        // Update a historical file version.
        JSONObject historyVersionsInfo = historyVersionsUpdate(url, access_token, fileId, historyVersionId);
        System.out.println(historyVersionsInfo.toJSONString());
    }

    private static JSONObject historyVersionsUpdate(String url, String access_token, String fileId, String historyVersionId) throws IOException {
        StringBuilder stringBuilder = new StringBuilder("");
        stringBuilder.append("/").append(fileId).append("/").append("historyVersions").append("/").append(historyVersionId);
        stringBuilder.append("?").append("fields=*");
        HttpPatch httpPatch = new HttpPatch(url + stringBuilder);
        httpPatch.setHeader("Authorization","Bearer " + access_token);
        httpPatch.setHeader("Content-Type", "application/json");
        httpPatch.setHeader("Accept", "application/json");

        JSONObject jsonParam = new JSONObject();
        jsonParam.put("keepPermanent", "true");
        StringEntity entity = new StringEntity(jsonParam.toString());
        entity.setContentType("application/json");
        httpPatch.setEntity(entity);

        CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch);

        try {
            HttpEntity responseEntity = response.getEntity();
            String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
            JSONObject jsonObject = (JSONObject) JSON.parse(ret);
            EntityUtils.consume(responseEntity);
            return jsonObject;
        }finally {
            response.close();
        }
    }