By calling the Files.create.resume API, your app can initialize the resumable upload task, including processing the file metadata and obtaining the location information for resumable upload, and can save the related file metadata for use by the Files.resume API.
Protocol | HTTP POST |
|---|---|
Direction | Developer server -> HUAWEI Drive server |
URL | https://driveapis.cloud.huawei.com.cn/upload/drive/v1/files?uploadType=resume |
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. |
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. |
POST https://driveapis.cloud.huawei.com.cn/upload/drive/v1/files?uploadType=resume&fields=* HTTP/1.1
Content-Type: application/json
X-Upload-Content-Type: image/jpeg
X-Upload-Content-Length: 200000
Authorization: Bearer CV3PnPLZXyr9K2GV7RYZkF962JZvoEkMQhTho3QHQAPQUyma/lEyZskP/IMWrc7FvaeHivO7y0lyibI/fQvulBnTgtXArSVPsjaLKvYNkDsJSaI
R2/sx+K40bYDWWpKFvJNKg2U47jRwz2mfiF3ortNk
Cache-Control: no-cache
{
"fileName": "HWTest001"
} 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 | Integer | Slice size. |
{
"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-8
Content-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 | 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 and access token.
String url = "https://driveapis.cloud.huawei.com.cn/upload/drive/v1/files";
String access_token = "CF3pvqiyaVUXfclpdiztAQIRcW/gGlZzV0HAiJBRe4ClGDYseeS6/PA2FMdMvfSc1vMKwzKJn0ZNPQZglHbpjQvscQA8yj0wmlMz2lhESZoa+pruIHCYQw==";
// Create a file and prepare for resumable upload.
String fileInfo = filesCreateResume(url, access_token);
if(fileInfo != null){
System.out.println(fileInfo);
}
}
private static String filesCreateResume(String url, String access_token) throws IOException {
StringBuilder stringBuilder = new StringBuilder("");
stringBuilder.append("?").append("fields=*");
stringBuilder.append("&").append("uploadType=resume");
HttpPost httpPost = new HttpPost(url + stringBuilder);
httpPost.setHeader("Authorization","Bearer " + access_token);
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("X-Upload-Content-Type", "image/jpeg");
httpPost.setHeader("X-Upload-Content-Length", "8023");
JSONObject jsonParam = new JSONObject();
jsonParam.put("fileName", "HWTest001");
StringEntity entity = new StringEntity(jsonParam.toString());
entity.setContentType("application/json");
httpPost.setEntity(entity);
CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost);
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();
}
}