文档管理中心
我的
API参考云空间服务RESTFilesFiles:get

Files:get

功能介绍

获取文件元数据。

场景描述

您的应用可以通过Files.get接口获取文件元数据。

使用约束

  • fields填*时,drive#file 结构中sharer、sharedWithMeTime、hasShared、capabilities、permissions、permissionIds不返回。
  • Scope至少包含下面其中一个:
    • https://www.huawei.com/auth/drive.appdata
    • 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.metadata
    • https://www.huawei.com/auth/drive.metadata.readonly

接口原型

承载协议

HTTP GET

接口方向

开发者服务器->华为云空间服务器

接口URL

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

数据格式

请求消息:Content-Type: application/json

响应消息:Content-Type: application/json

路径参数

展开

参数

是否必选

参数类型

描述

fileId

是

string

文件ID。

查询参数

展开

参数

是否必选

参数类型

描述

fields

否

string

采用[Partial-response格式],具体使用见公共说明。

form

否

string

媒体格式。

prettyPrint

否

boolean

是否以美观格式输出。

quotaId

否

string

用户标识,小于40个字符。用于限制单个用户的API访问数量。

callback

否

string

JSONP的callback函数。

请求参数

Request Header

展开

参数

是否必选

参数类型

描述

Authorization

是

string

用户鉴权信息 AccessToken(即AT)

x-hw-trace-id

否

string

业务跟踪id。

x-hw-app-id

否

string

应用的appid。

version

否

string

SDK版本。

x-hw-terminal

否

string

终端型号。

x-hw-os

否

string

终端操作系统类型。

unionID

否

string

用户的unionID。

User-Agent

否

string

应用版本号/appid。

x-hw-deviceUUID

否

string

设备UUID。

x-hw-deviceUDID

否

string

设备UDID。

x-hw-appPackageName

否

string

应用包名。

x-hw-network

否

string

网络类型,[WiFi, 2G, 3G, 4G, 5G, wire]。

Request Body

无

请求示例

GET https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABgL5WYKCuoCLU7sHD9P43gVTuocMgrsA?fields=* HTTP/1.1 
Accept: application/json 
Cache-Control: no-cache 
Authorization: Bearer CF3NTYZSs7MRmxWyj8ssonQQxDgSPAjnDvrf+91NrpN22LdUrMA30A5Kzz0mf55sWao7e7VeLrmjQ0z2OmwPWlt3S00/L1BJppbTFhIgWb74ZBK8CFImUA==

响应参数

状态码为200时:

展开

参数

参数类型

描述

category

string

类型,固定为drive#file。

id

string

文件id。

fileName

string

文件名。

mimeType

string

文件类型,具体取值参照公共说明。

description

string

文件描述。

favorite

boolean

文件是否被收藏。

recycled

boolean

文件是否被放入回收站。

directlyRecycled

boolean

文件是否被直接被放入回收站。

recyclingUser.category

string

类型,固定为drive#user。

recyclingUser.displayName

string

用户显示名。

recyclingUser.profilePhotoLink

string

用户头像链接(默认不返回)。

recyclingUser.me

boolean

是否是我。

recyclingUser.permissionId

string

权限id。

recyclingUser.userAccount

string

帐号名称(默认不返回)。

recycledTime

string

放入回收站的时间。

parentFolder[]

string

父目录。

properties

string

文件公共自定义属性。

appSettings

string

应用自定义属性。

containers[]

string

空间:drive,applicationData。

version

integer

版本号。

contentDownloadLink

string

文档下载链接。

iconDownloadLink

string

图标链接。

existThumbnail

boolean

是否有缩略图。

thumbnailDownloadLink

string

大缩略图链接。

smallThumbnailDownloadLink

string

小缩略图链接。

thumbnailVersion

integer

缩略图版本号。

onLineViewLink

string

在线浏览链接。

createdTime

string

文件创建时间。

editedTime

string

文件修改时间。

editedByMeTime

string

我修改文件的时间。

editedByMe

boolean

是否是我修改文件。

sharedWithMeTime

string

共享给我的时间。

sharer.category

string

类型,固定为drive#user。

sharer.displayName

string

用户显示名。

sharer.profilePhotoLink

string

用户头像链接(默认不返回)。

sharer.me

boolean

是否是我。

sharer.permissionId

string

权限id。

sharer.userAccount

string

帐号名称(默认不返回)。

owners.category

string

类型,固定为drive#user。

owners.displayName

string

用户显示名。

owners.profilePhotoLink

string

用户头像链接(默认不返回)。

owners.me

boolean

是否是我。

owners.permissionId

string

权限id。

owners.userAccount

string

帐号名称(默认不返回)。

lastEditor.category

string

类型,固定为drive#user。

lastEditor.displayName

string

用户显示名。

lastEditor.profilePhotoLink

string

用户头像链接(默认不返回)。

lastEditor.me

boolean

是否是我。

lastEditor.permissionId

string

权限id。

lastEditor.userAccount

string

帐号名称(默认不返回)。

hasShared

boolean

是否共享。

ownedByMe

boolean

是否是我用。

capabilities.addChildNodePermission

boolean

是否可以增加子目录/文件。

capabilities.writerHasChangeCopyPermission

boolean

change copy是否需要write权限。

capabilities.commentPermission

boolean

是否可以评论。

capabilities.copyPermission

boolean

是否可以拷贝。

capabilities.deletePermission

boolean

是否可以删除。

capabilities.downloadPermission

boolean

是否可以下载内容。

capabilities.editPermission

boolean

是否可以编辑。

capabilities.listChildNodePermission

boolean

是否可以list子目录/文件。

capabilities.editContentPermission

boolean

是否可以修改内容。

capabilities.readHistoryVersionPermission

boolean

是否可以读取副本。

capabilities.removeChildNodePermission

boolean

是否可以移动子目录。

capabilities.renameFilePermission

boolean

是否可以重命名。

capabilities.shareFilePermission

boolean

是否可以共享。

capabilities.recyclePermission

boolean

是否可以移动到回收站。

capabilities.unrecyclePermission

boolean

是否可以撤销移动子文件到回收站。

viewersHasCopyContentPermission

boolean

浏览者是否可以拷贝内容。

writerHasCopyPermission

boolean

拷贝是否需要writer权限。

writersHasSharePermission

boolean

writer能否share。

permissions[]

list

permission列表。

permission.category

string

类型,固定为drive#permission。

permission.id

string

权限ID。

permission.type

string

类型,[user,anyone]。

permission.role

string

角色,[owner,writer,commenter,reader]。

permission.userAccount

string

帐号名称。

permission.displayName

string

名称。

permission.expirationTime

string

失效时间。

permission.deleted

boolean

权限是否已删除。

permission.canDiscoverFile

boolean

是否允许被搜索(仅适用于anyone类型)。

permissionIds

list

permissionId列表。

originalFilename

string

原始文件名。

fullFileSuffix

string

完整的文件后缀,取name第一个.后的字符串。

fileSuffix

string

文件后缀,fullFileSuffix最后一个字符串。

size

integer

文件大小。

occupiedSpace

integer

实际占用空间大小。

pictureMetadata.width

integer

照片宽度。

pictureMetadata.height

integer

照片高度。

pictureMetadata.location.latitude

number

纬度。

pictureMetadata.location.longitude

number

经度。

pictureMetadata.location.altitude

number

高度。

pictureMetadata.exifTime

string

照片的时间,EXIF DateTime。

pictureMetadata.cameraMaker

string

照相机制造商。

pictureMetadata.cameraModel

string

照相机型号。

pictureMetadata.exposureTime

number

曝光长度,单位秒。

pictureMetadata.aperture

number

光圈,f-number。

pictureMetadata.flashUsed

boolean

是否使用闪光灯。

pictureMetadata.focalLength

number

焦距,毫米。

pictureMetadata.isoSpeed

integer

ISO速度。

pictureMetadata.meteringMode

string

测距模式。

pictureMetadata.sensor

string

感光类型。

pictureMetadata.exposureMode

string

曝光模式。

pictureMetadata.colorSpace

string

色彩空间。

pictureMetadata.whiteBalance

string

白平衡模式。

pictureMetadata.exposureBias

number

曝光偏差,APEX值。

pictureMetadata.maxApertureValue

number

最大光圈值,APEX value。

pictureMetadata.lens

string

镜头。

videoMetadata.width

integer

视频宽度。

videoMetadata.height

integer

视频高度。

videoMetadata.durationTime

integer

时长,毫秒。

sha256

string

文件的sha256。

lastHistoryVersionId

string

最新的历史记录版本ID。

contentVersion

string

内容版本号。

响应示例

{
    "fileName":"noname1592018273751",
    "sha256":"e24a16f95fed4f6ac502cc1a6a45dc4a75499aca75945834a44cb2e6deb17309",
    "owners":[
        {
            "permissionId":"239046878371512704",
            "displayName":"*******3121@**3.com",
            "me":true,
            "category":"drive#user"
        }
    ],
    "hasShared":false,
    "mimeType":"text/html",
    "permissionIds":[
        "239046878371512704"
    ],
    "lastHistoryVersionId":"ABgIbv7QCuoCLU1nhOVP43gVTWGE6ArsA",
    "parentFolder":[
        "AgFovWXIAIYANC20H_1Fj3oMLbIf8ACAA"
    ],
    "recycled":false,
    "directlyRecycled":false,
    "permissions":[
        {
            "role":"owner",
            "deleted":false,
            "displayName":"*******3121@**3.com",
            "id":"239046878371512704",
            "category":"drive#permission",
            "type":"user",
            "allowFileDiscovery":true
        }
    ],
    "occupiedSpace":13751,
    "createdTime":"2020-06-13T03:17:55.000Z",
    "id":"ABgIbv7QCuoCLU1nhOVP43gVTWGE6ArsA",
    "contentDownloadLink":"https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABgIbv7QCuoCLU1nhOVP43gVTWGE6ArsA?form=content",
    "capabilities":{
        "downloadPermission":true,
        "renameFilePermission":true,
        "commentPermission":true,
        "deletePermission":true,
        "readHistoryVersionPermission":true,
        "recyclePermission":true,
        "addChildNodePermission":false,
        "unrecyclePermission":true,
        "writerHasChangeCopyPermission":false,
        "copyPermission":true,
        "editContentPermission":true,
        "removeChildNodePermission":false,
        "editPermission":true,
        "listChildNodePermission":false,
        "shareFilePermission":true
    },
    "ownedByMe":true,
    "version":1592018138000,
    "writersHasSharePermission":true,
    "iconDownloadLink":"https://event-dre.dbankcdn.com/filemanagerpic/201911140913476Sc7.png",
    "editedTime":"2020-06-13T03:17:55.000Z",
    "size":13751,
    "thumbnailVersion":0,
    "lastEditor":{
        "permissionId":"239046878371512704",
        "displayName":"*******3121@**3.com",
        "me":true,
        "category":"drive#user"
    },
    "existThumbnail":false,
    "containers":[
        "drive"
    ],
    "category":"drive#file",
    "contentVersion":"bf604a7b-b990-35db-8428-05ce577b5c92"
}

常见错误码

错误码后4位为业务错误码,用于区分错误场景,其他业务错误码见状态码章节。

展开

状态码

错误码

响应代码

描述

200

NA

-

成功。

400

21004001

LACK_OF_PARAM

缺少入参,请检查参数列表。

400

21004002

PARAM_INVALID

参数校验失败,请检查参数列表。

403

21004032

SERVICE_NOT_SUPPORT

服务不支持。

403

21004035

INSUFFICIENT_SCOPE

Scope校验失败。

403

21004036

INSUFFICIENT_PERMISSION

角色权限不足。

500

21005006

SERVER_TEMP_ERROR

服务器异常。

403

21074033

AGREEMENT_NOT_SIGNED

用户还未签署华为云空间用户协议,请签署协议后再进行重试。

403

21084031

DATA_MIGRATING

正处于安全策略更新, 请等待安全策略更新完成。

500

21085002

OUTER_SERVICE_UNAVAILABLE

服务器异常。

500

21085006

SERVER_TEMP_ERROR

服务器异常。

调用示例

    public static void main(String[] args) throws IOException {
        // 设置请求地址,文件ID和用户认证信息
        String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/files";
        String fileId = "AAAKTnFgAIYCkUs9n_FB9ewNSzuf_ACAA";
        String access_token = "CF3mCevCXcxlfnkkJ+07JEYRgb6x/vVEerMg6zfmk/8X/3ZrZfIuxlAD6U37YdyXxZUjmWnwC64gdnOSMPzZ294fhEFdbBP05h1N+GeHcrEeyPltSPIUvw==";
        // 获取文件元数据
        JSONObject fileInfo = filesGet(url, access_token, fileId);
        System.out.println(fileInfo.toJSONString());
    }

    private static JSONObject filesGet(String url, String access_token, String fileId) throws IOException {
        StringBuilder stringBuilder = new StringBuilder("");
        stringBuilder.append("/").append(fileId);
        stringBuilder.append("?").append("fields=*");
        HttpGet httpGet = new HttpGet(url + stringBuilder);
        httpGet.setHeader("Authorization","Bearer " + access_token);
        CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet);

        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();
        }
    }