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
ReferencesDrive KitRESTFilesFiles:update

Files:update

Function

Updates file metadata.

Scenario

By calling the Files.update API, your app can update file metadata and soft-delete files.

Restrictions

  • If fields is set to *, sharer, sharedWithMeTime, hasShared, capabilities, permissions, and permissionIds in drive#file are not returned.
  • The value of scope must be one of the following:
    • https://www.huawei.com/auth/drive.appdata
    • https://www.huawei.com/auth/drive.file
    • https://www.huawei.com/auth/drive

Prototype

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

Path Parameters

Expand

Parameter

Mandatory/Optional

Type

Description

fileId

Mandatory

string

File ID.

Query Parameters

Expand

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 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.

baseVersion

Optional

integer

Base version.

mergeStrategy

Optional

string

Strategy for resolving version conflict.

  • save-if-unchanged: Use the strategy specified by the client.

  • save-if-unconflicted: Save upon no conflict, which is used for batch processing when atomic is set to false. In other cases, use the strategy specified by the client.

  • last-writer-wins: Process the higher version first.

  • current-writer-wins: Process the current version first.

Request Body

Expand

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.

Request Example

Collapse
Word wrap
Dark theme
Copy code
  1. PATCH https://driveapis.cloud.huawei.com.cn/drive/v1/files/DSQpEkxcAAADKXEPJAYABgOUVrNwA8Cu?fields=* HTTP/1.1
  2. Accept:application/json
  3. Content-Type: application/json
  4. Cache-Control: no-cache
  5. Authorization: Bearer CV3PnPLZXyr9K2GV7RYZkF962JZvoEkMQhTho3QHQAPQUyma/lEyZskP/IMWrc7FvaeHivO7y0lyibI/fQvulBnTgtXArSVPsjaLKvYNkDsJSaIR2/sx+K40bYDWWpKFvJNKg2U47jRwz2mfiF3ortNk
  6. Cache-Control: no-cache
  7. {
  8. "favorite": false,
  9. "fileName":"HuaweiTest22",
  10. "recycled":false,
  11. "description": "update file info",
  12. "originalFilename":"ori",
  13. "writerHasCopyPermission":false,
  14. "writersHasSharePermission":false,
  15. "properties": {
  16. "k1": "v1",
  17. "k2": "v2",
  18. "k3": "v3"
  19. },
  20. "appSettings": {
  21. "k1": "v1",
  22. "k2": "v2",
  23. "k3": "v3"
  24. }
  25. }

Response Parameters

When the status code is 200:

Expand

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.

Response Example

Collapse
Word wrap
Dark theme
Copy code
  1. {
  2. "fileName":"HuaweiTest22",
  3. "sha256":"e24a16f95fed4f6ac502cc1a6a45dc4a75499aca75945834a44cb2e6deb17309",
  4. "owners":[
  5. {
  6. "permissionId":"239046878371512704",
  7. "displayName":"*******3121@**3.com",
  8. "me":true,
  9. "category":"drive#user"
  10. }
  11. ],
  12. "hasShared":false,
  13. "mimeType":"text/html",
  14. "permissionIds":[
  15. "239046878371512704"
  16. ],
  17. "lastHistoryVersionId":"ABgIbv7QCuoCLU1nhOVP43gVTWGE6ArsA",
  18. "parentFolder":[
  19. "AgFovWXIAIYANC20H_1Fj3oMLbIf8ACAA"
  20. ],
  21. "recycled":false,
  22. "directlyRecycled":false,
  23. "permissions":[
  24. {
  25. "role":"owner",
  26. "deleted":false,
  27. "displayName":"*******3121@**3.com",
  28. "id":"239046878371512704",
  29. "category":"drive#permission",
  30. "type":"user",
  31. "allowFileDiscovery":true
  32. }
  33. ],
  34. "occupiedSpace":13751,
  35. "createdTime":"2020-06-13T03:17:55.000Z",
  36. "id":"ABgIbv7QCuoCLU1nhOVP43gVTWGE6ArsA",
  37. "contentDownloadLink":"https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABgIbv7QCuoCLU1nhOVP43gVTWGE6ArsA?form=content",
  38. "capabilities":{
  39. "downloadPermission":true,
  40. "renameFilePermission":true,
  41. "commentPermission":true,
  42. "deletePermission":true,
  43. "readHistoryVersionPermission":true,
  44. "recyclePermission":true,
  45. "addChildNodePermission":false,
  46. "unrecyclePermission":true,
  47. "writerHasChangeCopyPermission":false,
  48. "copyPermission":true,
  49. "editContentPermission":true,
  50. "removeChildNodePermission":false,
  51. "editPermission":true,
  52. "listChildNodePermission":false,
  53. "shareFilePermission":true
  54. },
  55. "ownedByMe":true,
  56. "version":1592018138000,
  57. "writersHasSharePermission":true,
  58. "iconDownloadLink":"https://event-dre.dbankcdn.com/filemanagerpic/201911140913476Sc7.png",
  59. "editedTime":"2020-06-13T03:17:55.000Z",
  60. "size":13751,
  61. "thumbnailVersion":0,
  62. "lastEditor":{
  63. "permissionId":"239046878371512704",
  64. "displayName":"*******3121@**3.com",
  65. "me":true,
  66. "category":"drive#user"
  67. },
  68. "existThumbnail":false,
  69. "containers":[
  70. "drive"
  71. ],
  72. "category":"drive#file",
  73. "contentVersion":"bf604a7b-b990-35db-8428-05ce577b5c92"
  74. }

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.

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.

Call Example

Collapse
Word wrap
Dark theme
Copy code
  1. public static void main(String[] args) throws IOException {
  2. // Set the request URL, file ID, and access token.
  3. String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/files";
  4. String fileId = "AgDK9uUMK-YAkYuFC51qle4Ni4MLkCvgA";
  5. String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ==";
  6. // Update file metadata.
  7. JSONObject fileInfo = filesUpdate(url, access_token, fileId);
  8. System.out.println(fileInfo.toJSONString());
  9. }
  10. private static JSONObject filesUpdate(String url, String access_token, String fileId) throws IOException {
  11. StringBuilder stringBuilder = new StringBuilder("");
  12. stringBuilder.append("/").append(fileId);
  13. stringBuilder.append("?").append("fields=*");
  14. HttpPatch httpPatch = new HttpPatch(url + stringBuilder);
  15. httpPatch.setHeader("Authorization","Bearer " + access_token);
  16. httpPatch.setHeader("Content-Type", "application/json");
  17. httpPatch.setHeader("Accept", "application/json");
  18. JSONObject jsonParam = new JSONObject();
  19. jsonParam.put("fileName", "HWFile001");
  20. StringEntity entity = new StringEntity(jsonParam.toString());
  21. entity.setContentType("application/json");
  22. httpPatch.setEntity(entity);
  23. CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch);
  24. try {
  25. HttpEntity responseEntity = response.getEntity();
  26. String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
  27. JSONObject jsonObject = (JSONObject) JSON.parse(ret);
  28. EntityUtils.consume(responseEntity);
  29. return jsonObject;
  30. }finally {
  31. response.close();
  32. }
  33. }
Search in References
Enter a keyword.