By calling the Files.update.resume API, your app can initialize the update task for resumable upload, including updating existing file metadata incrementally, parsing the file metadata, and obtaining location for the Files.resume API.
Protocol | HTTP PATCH |
|---|---|
Direction | Developer server -> HUAWEI Drive server |
URL | https://driveapis.cloud.huawei.com.cn/upload/drive/v1/files/{fileId}?uploadType=resume&fields=* |
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. The value is always resume. |
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. |
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. |
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-Upload-Content-Type | Optional | string | ID used for service tracing. |
X-Upload-Content-Length | Mandatory | integer | Content-Length of the file to be uploaded. |
x-hw-trace-id | Optional | string | ID used for service tracing. |
x-hw-app-id | Optional | string | App ID. |
x-hw-terminal | Optional | string | Device model. |
version | Optional | string | SDK version number. |
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
Parameter | Mandatory/Optional | Type | Description |
|---|---|---|---|
appSettings | Optional | string | Customized app attribute. |
contentExtras.thumbnail.content | Optional | string | Thumbnail data encoded with Base64. |
contentExtras.thumbnail.mimeType | Optional | string | MIME type of the thumbnail. |
writerHasCopyPermission | Optional | boolean | Indicates whether the current user (assuming the writer role) has permission to copy the file. |
createdTime | Optional | string | Time when the file is created. |
description | Optional | string | Short description of the file. |
mimeType | Optional | string | 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. |
parentFolder[] | Optional | string | Parent folder. The value can be root, applicationData, or the ID of a common folder. |
properties | Optional | string | Custom file properties that are universally visible. |
favorite | Optional | boolean | 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. |
sha256 | Optional | string | SHA-256 value for the file. |
PATCH https://driveapis.cloud.huawei.com.cn/upload/drive/v1/files/DSQpEkxcAAADKXEPJAYABgEZivNwAmCu?uploadType=resume&fields=* HTTP/1.1
X-Upload-Content-Type: image/jpeg
X-Upload-Content-Length: 200000
Authorization: Bearer CV3PnPLZXyr9K2GV7RYZkF962JZvoEkMQhTho3QHQAPQUyma/lEyZskP/IMWrc7FvaeHivO7y0lyibI/fQvulBnTgtXArSVPsjaLKvYNkDsJSaIR2/sx+K40bYDWWpKFvJNKg2U47jRwz2mfiF3ortNk
Cache-Control: no-cache
{
"appSettings":{
"test1":"value1"
},
"contentExtras":{
"thumbnail":{
"content":"***",
"mimeType":"image/jpeg",
"thumbnailPublic":false
}
},
"writerHasCopyPermission":false,
"createdTime":"2019-11-14T07:53:24.953Z",
"description":"test test test zb",
"mimeType":"image/jpeg",
"editedTime":"2019-11-14T07:53:24.953Z",
"fileName":"1234.JPG",
"originalFilename":"3123.JPG",
"parentFolder":[
"/opt/test"
],
"properties":{
"test2":"value2"
},
"favorite":true,
"writersHasSharePermission":false
} When the status code is 200:
Parameter | Type | Description |
|---|---|---|
Location | string | URI for the resumable upload session, where serverId indicates the ID of the server host for the resumable upload. Example: https://driveapis.cloud.huawei.com.cn/upload/drive/v1/{{serverId}}/file |
{
"sliceSize":4194304
}
Headers:
Location:https://driveapis.cloud.huawei.com.cn/upload/drive/v1/fc7300dbe0280d39/files?fields=*&uploadType=resume&uploadId=324314495017204480
Content-Type: application/json; charset=utf-8Content-Length: 21 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 | 21034001 | LACK_OF_PARAM | Input parameter is missing. Check the parameter list. |
400 | 22034002 | PARAM_INVALID | Parameter verification failed. Check the parameter list. |
400 | 22234002 | PARAM_INVALID | Parameter verification failed. Check the parameter list. |
400 | 22084002 | PARAM_INVALID | Parameter verification failed. Check the parameter list. |
400 | 22034003 | PARAM_VALUE_NOT_SUPPORT | Invalid parameter. Check the parameter list. |
400 | 22034004 | PARAM_EXPIRED | The parameter is not supported. Check the parameter list. |
400 | 22054005 | SITE_NOT_FOUND | Unknown site information. |
400 | 22044002 | PARAM_INVALID | Parameter verification failed. Check the parameter list. |
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 | 22124032 | SERVICE_NOT_SUPPORT | The service is not open. |
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. Try again after the agreement is signed. |
403 | 22054034 | CROSS_SITE_NOT_SUPPORT | Cross-site functions are restricted. |
403 | 22234036 | INSUFFICIENT_PERMISSION | No permission. |
403 | 22034038 | 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 space. Expand the capacity or delete useless files, and try again. |
403 | 22234038 | OUTER_SERVICE_ERROR | External service error. |
403 | 22044035 | INSUFFICIENT_SCOPE | Scope verification failed. |
403 | 22234035 | INSUFFICIENT_SCOPE | Scope verification failed. |
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. |
429 | 22034291 | USER_REQUEST_TOO_MANY | Too many resumable upload initialization requests. |
500 | 22035005 | RESOURCE_LOCKED | The file is locked. |
500 | 22035004 | DATABASE_UNAVAILABLE | Database reading and writing failed. |
500 | 22005006 | SERVER_TEMP_ERROR | Temporary server error. |
500 | 22045002 | OUTER_SERVICE_UNAVAILABLE | External service is unavailable. |
500 | 22235002 | OUTER_SERVICE_UNAVAILABLE | External service is unavailable. |
500 | 22085006 | SERVER_TEMP_ERROR | Temporary server error. |
500 | 22085001 | SERVER_IS_BUSY | Insufficient server resources. |
500 | 22075002 | OUTER_SERVICE_UNAVAILABLE | External service is unavailable. |
500 | 22125002 | OUTER_SERVICE_UNAVAILABLE | External service is unavailable. |
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 = "AACWO19qK7wAg6gA2-kVh4QNqAzb5CuwA";
String access_token = "CF3p+5TNdpCs0OjI+bP04rVLLe6WJpFWefKlASOzIaDArxxS36ku2TePpHUGzfJAW4C4YO06wB7eIhMdu/MEOsqAkWu0rpNmVcTUsVefUSmt5RUvhAr2oQ==";
// Update a file and prepare for resumable upload.
String fileInfo = filesUpdatePatchresume(url, access_token, fileId);
if(fileInfo != null){
System.out.println(fileInfo);
}
}
private static String filesUpdatePatchresume(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=resume");
HttpPatch httpPatch = new HttpPatch(url + stringBuilder);
httpPatch.setHeader("Authorization","Bearer " + access_token);
httpPatch.setHeader("Content-Type", "application/json;charset=UTF-8");
httpPatch.setHeader("Accept", "*/*");
httpPatch.setHeader("X-Upload-Content-Length", "53");
JSONObject jsonParam = new JSONObject();
jsonParam.put("\"appSettings\"", "{ \"test1\": \"value1\" }");
StringEntity entity = new StringEntity(jsonParam.toString());
httpPatch.setEntity(entity);
CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch);
try {
if(response.getStatusLine().getStatusCode() == 200){
String ret = response.getHeaders("Location")[0].getValue();
return ret;
}
HttpEntity responseEntity = response.getEntity();
String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
JSONObject jsonObject = (JSONObject) JSON.parse(ret);
EntityUtils.consume(responseEntity);
return jsonObject.toJSONString();
}finally {
response.close();
}
}