Protocol | HTTP PATCH |
|---|---|
Direction | Developer server -> HUAWEI Drive server |
URL | https://driveapis.cloud.huawei.com.cn/upload/drive/v1/files/{fileId}?uploadType=content |
Data Format | Request: Content-Type: application/json Response: Content-Type: application/json |
Parameter | Mandatory/Optional | Type | Description |
|---|---|---|---|
uploadType | Mandatory | string | Type of an upload request. |
fields | Optional | string | Fields in the request, which are in the partial response format. For details, please refer to Overview. |
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. |
Cookie | Optional | string | Cookie, in which loginId is the session ID used for authentication. |
Request Body
File content.
PATCH https://driveapis.cloud.huawei.com.cn/upload/drive/v1/files/AB9FfdS4CuoCKgB0ro1P43gSAHKugArsA?uploadType=content&fields=* HTTP/1.1 Content-Type: image/jpeg Content-Length: 200000 Authorization: Bearer CV3PnPLZXyr9K2GV7RYZkF962JZvoEkMQhTho3QHQAPQUyma/lEyZskP/IMWrc7FvaeHivO7y0lyibI/fQvulBnTgtXArSVPsjaLKvYNkDsJSaIR2/sx+K40bYDWWpKFvJNKg2U47jRwz2mfiF3ortNk Cache-Control: no-cache [imageData]
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 | MIME type of the file. |
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 | Type of the grantee, which can be user or 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 fullFileExtension. |
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":"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"
} 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 | 22014001 | LACK_OF_PARAM | Input parameter is missing. |
400 | 22014002 | PARAM_INVALID | Parameter verification failed. |
400 | 22234002 | PARAM_INVALID | Parameter verification failed. |
400 | 22014003 | PARAM_VALUE_NOT_SUPPORT | Invalid parameter. |
400 | 22014004 | PARAM_EXPIRED | The parameter value is not supported. |
400 | 22054005 | SITE_NOT_FOUND | Unknown site information. |
401 | 22044011 | USER_NOT_AUTHORIZED | User authentication failed. |
403 | 22124031 | DATA_MIGRATINT | The security policy is being updated. Please wait until the update is complete. |
403 | 22004032 | SERVICE_NOT_SUPPORT | The service is not supported in the current country/region. |
403 | 22044033 | AGREEMENT_NOT_SIGNED | The agreement is not signed. |
403 | 22054034 | CROSS_SITE_NOT_SUPPORT | Cross-site functions are restricted. |
403 | 22004035 | INSUFFICIENT_SCOPE | Scope verification failed. |
403 | 22234035 | INSUFFICIENT_SCOPE | Scope verification failed. |
403 | 22234036 | INSUFFICIENT_PERMISSION | No permission. |
403 | 22014038 | OUTER_SERVICE_ERROR | An external service error occurred and cannot be rectified. |
403 | 22234038 | OUTER_SERVICE_ERROR | An external service error occurred and cannot be rectified. |
403 | 22114039 | SPACE_FULL | Insufficient storage space. |
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 | 22015002 | OUTER_SERVICE_UNAVAILABLE | External service is unavailable. |
500 | 22235002 | OUTER_SERVICE_UNAVAILABLE | External service is unavailable. |
500 | 22005006 | SERVER_TEMP_ERROR | Temporary 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/upload/drive/v1/files";
String fileId = "AACeJVrcK7wAg6Ae3l8Vh4QNoBLeUiuwA";
String access_token = "CF3pA9N/bBr1lFcpPsK7v1W9gtIScpAxfsR0VDiTsCj8TIZwQG4yGBaTYHTQgxVXoVcYgXw+hAhMTE904csrrkQ6v7+RhRm8C6yIEOnDi3YteB3bvyj40w==";
// Update a file in content mode and upload it to Drive.
JSONObject fileInfo = filesUpdatePatchcontent(url, access_token, fileId);
System.out.println(fileInfo.toJSONString());
}
private static JSONObject filesUpdatePatchcontent(String url, String access_token, String fileId) throws IOException {
StringBuilder stringBuilder = new StringBuilder("");
stringBuilder.append("/").append(fileId);
stringBuilder.append("?").append("fields=*");
stringBuilder.append("&").append("uploadType=content");
HttpPatch httpPatch = new HttpPatch(url + stringBuilder);
httpPatch.setHeader("Authorization","Bearer " + access_token);
httpPatch.setHeader("Content-Type", "image/jpeg");
httpPatch.setHeader("Accept", "application/json");
httpPatch.setHeader("X-Upload-Content-Type", "image/jpeg");
File file = new File("C:\\Users\\z00502234\\Pictures\\Saved Pictures\\0.jpg"); // Change the file path to your local path.
if(!file.exists()){
System.out.print("File not exist");
return null;
}
FileBody bin = new FileBody(file, ContentType.create("image/jpeg", Consts.UTF_8));
HttpEntity entity = MultipartEntityBuilder
.create()
.setCharset(Charset.forName("utf-8"))
.addPart("file", bin)
.build();
httpPatch.setEntity(entity);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(50000).setConnectionRequestTimeout(10000)
.setSocketTimeout(50000).build();
httpPatch.setConfig(requestConfig);
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();
}
}