智能客服
你问我答,随时在线为你解决问题
更新文件元数据。
您的应用可以通过Files.update接口更新文件元数据,进行文件软删除等。
| 承载协议 | HTTP PATCH |
|---|---|
| 接口方向 | 开发者服务器->华为云空间服务器 |
| 接口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格式],具体使用见公共说明。 |
| addParentFolder | 否 | string | 逗号分隔的父目录ID列表,注意只取第一个,不支持多父目录,addParentFolder必须和removeParentFolder成对出现。 |
| removeParentFolder | 否 | string | 逗号分隔的父目录ID列表,注意只取第一个,不支持多父目录,addParentFolder必须和removeParentFolder成对出现。 |
| form | 否 | string | 媒体格式。 |
| prettyPrint | 否 | boolean | 是否以美观格式输出。 |
| quotaId | 否 | string | 用户标识,小于40个字符。用于限制单个用户的API访问数量。 |
| callback | 否 | string | JSONP的callback函数。 |
| autoRename | 否 | string | 自动重命名,如果是true,或者不传,自动重命名;如果是false,则不会自动重命名。 |
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]。 |
| baseVersion | 否 | integer | 基础版本。 |
| mergeStrategy | 否 | string | 版本的冲突解决策略:
|
Request Body
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| appSettings | 否 | string | 应用自定义属性。 |
| writerHasCopyPermission | 否 | boolean | copy是否需要writer权限。 |
| description | 否 | string | 文件描述。 |
| mimeType | 否 | boolean | 文件类型,具体取值参照公共说明。 |
| editedTime | 否 | string | 文件修改时间。 |
| fileName | 否 | string | 文件名。 |
| originalFilename | 否 | string | 原始文件名。 |
| recycled | 否 | string | 回收状态,[true,false]。 |
| properties | 否 | string | 文件公共自定义属性。 |
| favorite | 否 | string | 文件是否被收藏。 |
| writersHasSharePermission | 否 | boolean | 写权限是否能分享。 |
- PATCH https://driveapis.cloud.huawei.com.cn/drive/v1/files/DSQpEkxcAAADKXEPJAYABgOUVrNwA8Cu?fields=* HTTP/1.1
- Accept:application/json
- Content-Type: application/json
- Cache-Control: no-cache
- Authorization: Bearer CV3PnPLZXyr9K2GV7RYZkF962JZvoEkMQhTho3QHQAPQUyma/lEyZskP/IMWrc7FvaeHivO7y0lyibI/fQvulBnTgtXArSVPsjaLKvYNkDsJSaIR2/sx+K40bYDWWpKFvJNKg2U47jRwz2mfiF3ortNk
- Cache-Control: no-cache
-
- {
- "favorite": false,
- "fileName":"HuaweiTest22",
- "recycled":false,
- "description": "update file info",
- "originalFilename":"ori",
- "writerHasCopyPermission":false,
- "writersHasSharePermission":false,
- "properties": {
- "k1": "v1",
- "k2": "v2",
- "k3": "v3"
- },
- "appSettings": {
- "k1": "v1",
- "k2": "v2",
- "k3": "v3"
- }
- }
状态码为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":"HuaweiTest22",
- "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 | 参数校验失败,请检查参数列表。 |
| 400 | 21004009 | PARENTFOLDER_NOT_FOUND | 父目录不存在,建议指定父目录后重试。 |
| 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 | 用户割接中,无法分享操作,请等待割接完成。 |
| 410 | 21084100 | CURSOR_EXPIRED | 游标过期,请重新获取游标。 |
| 410 | 21084101 | TEMP_DATA_CLEARD | 临时数据已经被清理,请重新获取游标。 |
| 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 = "AgDK9uUMK-YAkYuFC51qle4Ni4MLkCvgA";
- String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ==";
- // 更新文件元数据
- JSONObject fileInfo = filesUpdate(url, access_token, fileId);
- System.out.println(fileInfo.toJSONString());
- }
-
- private static JSONObject filesUpdate(String url, String access_token, String fileId) throws IOException {
- StringBuilder stringBuilder = new StringBuilder("");
- stringBuilder.append("/").append(fileId);
- 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("fileName", "HWFile001");
-
- 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();
- }
- }
-
-