We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

HistoryVersions:get.content

Function

Downloads a historical version of a file.

Scenario

By calling the HistoryVersions.get.content API, your app can download a historical file version.

Restrictions

  • Only the writer, owner, reader, commenter role can download a historical file version.
  • The value of scope must be one of the following:
    • https://www.huawei.com/auth/drive.file
    • https://www.huawei.com/auth/drive
    • https://www.huawei.com/auth/drive.readonly
    • https://www.huawei.com/auth/drive.appdata
  • The value of form must be the same as the value of content.

Prototype

Protocol

HTTP GET

Direction

Developer server -> HUAWEI Drive server

URL

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

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Path Parameters

Expand

Parameter

Mandatory/Optional

Type

Description

fileId

Mandatory

string

File ID.

historyVersionId

Mandatory

string

ID of a historical version.

Query Parameters

Expand

Parameter

Mandatory/Optional

Type

Description

form

Mandatory

string

Download mode, which is always content.

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.

Request Parameters

Request Header

Expand

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.

Cookie

Optional

string

Cookie, in which loginId is the session ID used for authentication.

Request Body

None.

Request Example

GET
https://driveapis.cloud.huawei.com.cn/drive/v1/files/BgZ_uIemYqVW0WYk0eNtKVYLMryFlmKjV/historyVersions/362238192574807808.362238192574807809?form=content HTTP/1.1
Authorization: Bearer
CgB6e3x9Bjh6m9tm8OB0GXjeMWk0m4pVnLmwteDNWXOKPhh0/tjwtIy6Q+OscvD7zhdrElYD0Rak6xA7dI4BM3GSQTuUgFK6ZwFk7K/fjJS5vB7JFmV3

Response Parameters

When the status code is 200:

Expand

Parameter

Type

Description

MediaContent

string

File content.

Response Example

HTTP/1.1 200 OK 
[imageData]

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.

Expand

Status Code

Result Code

Response Code

Description

200

NA

-

Success.

302

NA

-

You are redirected to another URL for download.

400

22004003

PARAM_VALUE_NOT_SUPPORT

The parameter is not supported. Check the parameter list.

400

22044002

PARAM_INVALID

Parameter verification failed. Check the parameter list.

400

22054002

PARAM_INVALID

Parameter verification failed. Check the parameter list.

400

22054003

PARAM_VALUE_NOT_SUPPORT

The parameter is not supported. Check the parameter list.

400

22054005

SITE_NOT_FOUND

Unknown site information.

400

22064001

LACK_OF_PARAM

Input parameter is missing. Check the parameter list.

400

22064002

PARAM_INVALID

Parameter verification failed. Check the parameter list.

400

22064003

PARAM_VALUE_NOT_SUPPORT

Invalid parameter. Check the parameter list.

400

22064004

PARAM_EXPIRED

The parameter is not supported. Check the parameter list.

400

22084002

PARAM_INVALID

Parameter verification failed. Check the parameter list.

400

22234002

PARAM_INVALID

Parameter verification failed. Check the parameter list.

401

22044011

USER_NOT_AUTHORIZED

User authentication failed.

401

22054011

USER_NOT_AUTHORIZED

User authentication failed.

401

22064011

USER_NOT_AUTHORIZED

User authentication failed.

403

22004032

SERVICE_NOT_SUPPORT

The service is not supported in the current country/region.

403

22004035

INSUFFICIENT_SCOPE

Scope verification failed.

403

22004037

OPERATION_NOT_COMPLETE

Operation failed due to an error.

403

22044033

AGREEMENT_NOT_SIGNED

The agreement is not signed. Try again after the agreement is signed.

403

22054034

CROSS_SITE_NOT_SUPPORT

Cross-site functions are restricted.

403

22064035

INSUFFICIENT_SCOPE

Scope verification failed.

403

22064036

INSUFFICIENT_PERMISSION

No permission.

403

22064038

OUTER_SERVICE_ERROR

An external service error occurred and cannot be rectified.

403

22124031

DATA_MIGRATINT

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

403

22124032

SERVICE_NOT_SUPPORT

The service is not open.

403

22234035

INSUFFICIENT_SCOPE

Scope verification failed.

403

22234036

INSUFFICIENT_PERMISSION

No permission.

403

22234038

OUTER_SERVICE_ERROR

An external service error occurred and cannot be rectified.

404

22234041

CONTENT_NOT_FOUND

The content is not found.

429

22074291

USER_REQUEST_TOO_MANY

Too many user requests.

429

22074292

APP_REQUEST_TOO_MANY

Too many app requests.

500

22005006

SERVER_TEMP_ERROR

Temporary server error.

500

22065002

OUTER_SERVICE_UNAVAILABLE

External service is unavailable.

500

22065005

RESOURCE_LOCKED

Resource locked and cannot be operated currently.

500

22085006

SERVER_TEMP_ERROR

Temporary server error.

500

22235002

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 = "AACUf44uK7wAg6pECq0Vh4QNqkgKoCuwA";
        String historyVersionId = "367254548466646784.367254548466646785";
        String access_token = "CF3qCeRPLh5GzjpB3ta5UscyjQa2rZhjgFzULNJqVDmCGCJi7IjrQwG7MKmpWIHTq6PRVeYSDsTZtjMbeCoP9ReANeBzHPYRHAppt8HZAaw/3H+IiLbWzQ==";
        // Download a historical version of a file.
        historyVersionGetMedia(url, access_token, fileId, historyVersionId);
    }

    private static void historyVersionGetMedia(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("form=content");
        HttpGet httpGet = new HttpGet(url + stringBuilder);
        httpGet.setHeader("Authorization","Bearer " + access_token);
        httpGet.setHeader("Cache-Control","no-cache");
        CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet);

        try {
            response.setHeader("Content-type","image/jpeg");
            HttpEntity responseEntity = response.getEntity();
            InputStream inputStream=responseEntity.getContent();
            FileUtils.copyToFile(inputStream, new File("D://2.jpg"));
        }finally {
            response.close();
        }
    }