By calling the Files.emptyRecycle API, your app can clear the recycle bin of a user's Drive or app data.
Protocol | HTTP DELETE |
|---|---|
Direction | Developer server -> HUAWEI Drive server |
URL | https://driveapis.cloud.huawei.com.cn/drive/v1/files/recycle |
Data Format | Request: Content-Type: application/json Response: Content-Type: application/json |
Parameter | Mandatory/Optional | Type | Description |
|---|---|---|---|
containers | Optional | string | Query scope. The value can be drive, applicationData, or a combination of the two (separated by a comma). The default value is drive. |
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. |
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. |
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. |
Request Body
None.
DELETE https://driveapis.cloud.huawei.com.cn/drive/v1/files/recycle HTTP/1.1 Accept: application/json Cache-Control: no-cache Authorization: Bearer CF3NTYZSs7MRmxWyj8ssonQQxDgSPAjnDvrf+91NrpN22LdUrMA30A5Kzz0mf55sWao7e7VeLrmjQ0z2OmwPWlt3S00/L1BJppbTFhIgWb74ZBK8CFImUA==
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 |
|---|---|---|---|
204 | 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. |
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 | The security policy is being updated. Please wait until the update is complete. |
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 and access token.
String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/files/recycle";
String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ==";
// Clear the recycle bin.
Boolean isTrash = false;
isTrash = filesEmptyTrash(url, access_token);
System.out.println(isTrash);
}
private static Boolean filesEmptyTrash(String url, String access_token) throws IOException {
HttpDelete httpDelete = new HttpDelete(url);
httpDelete.setHeader("Authorization","Bearer " + access_token);
CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpDelete);
try {
if(response.getStatusLine().getStatusCode() == 204){ // Status code 204 will be returned if the recycle bin is cleared successfully.
return true;
}
return false;
}finally {
response.close();
}
}