Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Updates file metadata.
By calling the Files.update API, your app can update file metadata and soft-delete files.
Protocol | HTTP PATCH |
|---|---|
Direction | Developer server -> HUAWEI Drive server |
URL | https://driveapis.cloud.huawei.com.cn/drive/v1/files/{fileId} |
Data Format | Request: Content-Type: application/json Response: Content-Type: application/json |
Parameter | Mandatory/Optional | Type | Description |
|---|---|---|---|
fileId | Mandatory | string | File ID. |
Parameter | Mandatory/Optional | Type | Description |
|---|---|---|---|
fields | Optional | string | Fields in the request, which are in the partial response format. For details, please refer to Overview. |
addParentFolder | Optional | string | A comma-separated list of parent IDs to add. Only the first parent ID on the list is used. Update requests must always use addParentFolder and removeParentFolder to modify the parent list. |
removeParentFolder | Optional | string | A comma-separated list of parent IDs to add. Only the first parent ID on the list is used. Update requests must always use addParentFolder and removeParentFolder to modify the parent list. |
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. |
autoRename | Optional | string | Indicates whether to automatically rename the file. If this parameter is set to true of left empty, the file will be automatically renamed. If this parameter is set to false, the file will not be automatically renamed. |
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. |
baseVersion | Optional | integer | Base version. |
mergeStrategy | Optional | string | Strategy for resolving version conflict.
|
Request Body
Parameter | Mandatory/Optional | Type | Description |
|---|---|---|---|
appSettings | Optional | string | Customized app attribute. |
writerHasCopyPermission | Optional | boolean | Indicates whether the current user (assuming the writer role) has permission to copy the file. |
description | Optional | string | Short description of the file. |
mimeType | Optional | boolean | File type. For details, please refer to Overview. |
editedTime | Optional | string | Last time when the file is modified. |
fileName | Optional | string | File name. |
originalFilename | Optional | string | Original file name. |
recycled | Optional | string | Recycling status. The value options include true and false. |
properties | Optional | string | Custom file properties that are universally visible. |
favorite | Optional | string | Indicates whether the file has been favorited. |
writersHasSharePermission | Optional | boolean | Indicates whether the current user (assuming the writer role) has permission to share the file. |
- 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"
- }
- }
When the status code is 200:
Parameter | Type | Description |
|---|---|---|
category | string | Resource type. The value is always drive#file. |
id | string | File ID. |
fileName | string | File name. |
mimeType | string | File type. For details, please refer to Overview. |
description | string | Short description of the file. |
favorite | boolean | Indicates whether the file has been favorited. |
recycled | boolean | Indicates whether the file has been moved to the recycle bin. |
directlyRecycled | boolean | Indicates whether the file has been explicitly moved to the recycle bin. |
recyclingUser.category | string | User type. The value is always drive#user. |
recyclingUser.displayName | string | Display name of the user. |
recyclingUser.profilePhotoLink | string | Link to the user's profile picture, which is not returned by default. |
recyclingUser.me | boolean | Indicates whether the user is the requesting user. |
recyclingUser.permissionId | string | Permission ID. |
recyclingUser.userAccount | string | Account of the user, which is not returned by default. |
recycledTime | string | Time when the file is moved to the recycle bin. |
parentFolder[] | string | Parent folder. |
properties | string | Custom file properties that are universally visible. |
appSettings | string | Customized app attribute. |
containers[] | string | Spaces that contain the file. The options include drive and applicationData. |
version | integer | Version number of the file. |
contentDownloadLink | string | Link for downloading the file in a browser. |
iconDownloadLink | string | Link to the file's icon. |
existThumbnail | boolean | Indicates whether the file has a thumbnail. |
thumbnailDownloadLink | string | Link to the file's large thumbnail. |
smallThumbnailDownloadLink | string | Link to the file's small thumbnail. |
thumbnailVersion | integer | Thumbnail version number. |
onLineViewLink | string | Link to view the file online. |
createdTime | string | Time when the file is created. |
editedTime | string | Last time when the file is modified. |
editedByMeTime | string | Last time when the file is modified by the user. |
editedByMe | boolean | Indicates whether the file is modified by the user. |
sharedWithMeTime | string | Time when the file is shared with the user. |
sharer.category | string | User type. The value is always drive#user. |
sharer.displayName | string | Display name of the user. |
sharer.profilePhotoLink | string | Link to the user's profile picture, which is not returned by default. |
sharer.me | boolean | Indicates whether the user is the requesting user. |
sharer.permissionId | string | Permission ID. |
sharer.userAccount | string | Account of the user, which is not returned by default. |
owners.category | string | User type. The value is always drive#user. |
owners.displayName | string | Display name of the user. |
owners.profilePhotoLink | string | Link to the user's profile picture, which is not returned by default. |
owners.me | boolean | Indicates whether the user is the requesting user. |
owners.permissionId | string | Permission ID. |
owners.userAccount | string | Account of the user, which is not returned by default. |
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. |
hasShared | boolean | Indicates whether the file is shared. |
ownedByMe | boolean | Indicates whether the user owns the file. |
capabilities.addChildNodePermission | boolean | Indicates whether the current user has permission to create subfolders or files to a folder. |
capabilities.writerHasChangeCopyPermission | boolean | Indicates whether the current user (assuming the writer role) has permission to change or copy the file. |
capabilities.commentPermission | boolean | Indicates whether the current user has permission to comment on the file. |
capabilities.copyPermission | boolean | Indicates whether the current user has permission to copy the file. |
capabilities.deletePermission | boolean | Indicates whether the current user has permission to delete the file. |
capabilities.downloadPermission | boolean | Indicates whether the current user has permission to download the file. |
capabilities.editPermission | boolean | Indicates whether the current user has permission to edit the file. |
capabilities.listChildNodePermission | boolean | Indicates whether the current user has permission to list subfolders or files in a folder. |
capabilities.editContentPermission | boolean | Indicates whether the current user has permission to modify the content of the file. |
capabilities.readHistoryVersionPermission | boolean | Indicates whether the current user has permission to read the historical versions of the file. |
capabilities.removeChildNodePermission | boolean | Indicates whether the current user has permission to remove subfolders from a folder. |
capabilities.renameFilePermission | boolean | Indicates whether the current user has permission to rename the file. |
capabilities.shareFilePermission | boolean | Indicates whether the current user has permission to share the file. |
capabilities.recyclePermission | boolean | Indicates whether the current user has permission to move the file to the recycle bin. |
capabilities.unrecyclePermission | boolean | Indicates whether the current user has permission to restore the file from the recycle bin. |
viewersHasCopyContentPermission | boolean | Indicates whether the current user has permission to copy the content of the file. |
writerHasCopyPermission | boolean | Indicates whether the current user (assuming the writer role) has permission to copy the file. |
writersHasSharePermission | boolean | Indicates whether the current user (assuming the writer role) has permission to share the file. |
permissions[] | list | List of permissions for the file. |
permission.category | string | Permission category. The value is always drive#permission. |
permission.id | string | Permission ID. |
permission.type | string | Grantee type. The options include user and anyone. |
permission.role | string | Role granted by the permission. The options include owner, writer, commenter, and reader. |
permission.userAccount | string | Account of the user. |
permission.displayName | string | Display name of the permission. |
permission.expirationTime | string | Time when the permission expires. |
permission.deleted | boolean | Indicates whether the permission is deleted. |
permission.canDiscoverFile | boolean | Indicates whether the permission allows the file to be searched. It is applicable only to permissions of the anyone type. |
permissionIds | list | List of permission IDs for users with access to the file. |
originalFilename | string | Original file name. |
fullFileSuffix | string | Full file name suffix extracted from the name field. It is the substring that comes immediately after the dot character in the file name. |
fileSuffix | string | Last component of fullFileSuffix. |
size | integer | File size. |
occupiedSpace | integer | Actual storage used by the file. |
pictureMetadata.width | integer | Picture width. |
pictureMetadata.height | integer | Picture height. |
pictureMetadata.location.latitude | number | Latitude stored in the picture. |
pictureMetadata.location.longitude | number | Longitude stored in the picture. |
pictureMetadata.location.altitude | number | Altitude stored in the picture. |
pictureMetadata.exifTime | string | Date and time when the picture is created (EXIF DateTime). |
pictureMetadata.cameraMaker | string | Maker of the camera that is used to create the picture. |
pictureMetadata.cameraModel | string | Model of the camera that is used to create the picture. |
pictureMetadata.exposureTime | number | Length of the exposure, in seconds. |
pictureMetadata.aperture | number | Aperture (f-number) used to create the picture. |
pictureMetadata.flashUsed | boolean | Indicates whether a flash is used to create the picture. |
pictureMetadata.focalLength | number | Focal length used to create the picture, in millimeters. |
pictureMetadata.isoSpeed | integer | ISO speed used to create the picture. |
pictureMetadata.meteringMode | string | Metering mode used to create the picture. |
pictureMetadata.sensor | string | Type of sensor used to create the picture. |
pictureMetadata.exposureMode | string | Exposure mode used to create the picture. |
pictureMetadata.colorSpace | string | Color space of the picture. |
pictureMetadata.whiteBalance | string | White balance mode used to create the picture. |
pictureMetadata.exposureBias | number | Exposure bias of the picture (APEX value). |
pictureMetadata.maxApertureValue | number | Maximum aperture used to create the picture (APEX value). |
pictureMetadata.lens | string | Lens used to create the picture. |
videoMetadata.width | integer | Width of the video. |
videoMetadata.height | integer | Height of the video. |
videoMetadata.durationTime | integer | Duration of the video, in milliseconds. |
sha256 | string | SHA-256 value for the file. |
lastHistoryVersionId | string | ID of the latest version. |
contentVersion | string | Content version number. |
- {
- "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"
- }
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 | 21004001 | LACK_OF_PARAM | Input parameter is missing. Check the parameter list. |
400 | 21004002 | PARAM_INVALID | Parameter verification failed. Check the parameter list. |
400 | 21004009 | PARENTFOLDER_NOT_FOUND | The parent folder does not exist. Specify a parent folder and try again. |
403 | 21004032 | SERVICE_NOT_SUPPORT | The service is not supported. |
403 | 21004035 | INSUFFICIENT_SCOPE | Scope verification failed. |
403 | 21004036 | INSUFFICIENT_PERMISSION | Insufficient role permission. |
500 | 21005006 | SERVER_TEMP_ERROR | Server error. |
403 | 21074033 | AGREEMENT_NOT_SIGNED | The HUAWEI Drive user agreement is not signed. Try again after the agreement is signed. |
403 | 21084031 | DATA_MIGRATINT | Sharing is not allowed during user migration. Try again after the migration is completed. |
410 | 21084100 | CURSOR_EXPIRED | The cursor has expired. Obtain a new cursor. |
410 | 21084101 | TEMP_DATA_CLEARD | Temporary data has been deleted. Obtain the cursor again. |
500 | 21085002 | OUTER_SERVICE_UNAVAILABLE | Server error. |
500 | 21085006 | SERVER_TEMP_ERROR | Server error. |
- public static void main(String[] args) throws IOException {
- // Set the request URL, file ID, and access token.
- String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/files";
- String fileId = "AgDK9uUMK-YAkYuFC51qle4Ni4MLkCvgA";
- String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ==";
- // Update file metadata.
- 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();
- }
- }
-
-