承载协议 | HTTP POST |
|---|---|
接口方向 | 开发者服务器->华为云空间服务器 |
接口URL | https://driveapis.cloud.huawei.com.cn/batch/drive/v3 |
数据格式 | 请求消息:Content-Type: multipart/mixed;boundry=XXX |
固定格式为
--XXX 请求1总Headers 请求1 headers1 body1(非必填) --XXX 请求2总Headers 请求2 headers2 body2(非必填) --XXX--
POST https://driveapis.cloud.huawei.com.cn/batch/drive/v3 HTTP/1.1
Content-Type: multipart/mixed; boundary=END_OF_PART
--END_OF_PART
Content-Type: application/http
Content-Transfer-Encoding: binary
GET https://driveapis.cloud.huawei.com.cn/drive/v1/about?fields=*
Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du
--END_OF_PART
Content-Type: application/http
Content-Transfer-Encoding: binary
POST https://driveapis.cloud.huawei.com.cn/drive/v1/files?fields=*
Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du
Content-Type: application/json
{
"fileName":"driveTest1",
"favorite":"true",
"description":"folder",
"mimeType":"application/vnd.huawei-apps.folder"
}
--END_OF_PART
Content-Type: application/http
Content-Transfer-Encoding: binary
GET https://driveapis.cloud.huawei.com.cn/drive/v1/files?fields=files(id,mimeType)
Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du
Content-Type: application/json
--END_OF_PART
Content-Type: application/http
Content-Transfer-Encoding: binary
GET https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA?fields=*
Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du
Content-Type: application/json
--END_OF_PART
Content-Type: application/http
Content-Transfer-Encoding: binary
PATCH https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA?fields=*
Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du
Content-Type: application/json
{
"fileName":"driveTest2"
}
--END_OF_PART
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA?fields=*
Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du
Content-Type: application/json
--END_OF_PART-- --batch8ffaa9960b344534981a5c7ad7bbda81
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 200 OK
Content-type: application/json
content-length: 399
Content-Length: 399
{"storageQuota":{"usedSpace":"13751","userCapacity":"5368709120"},"maxThumbnailSize":2097152,"needUpdate":false,"maxFileUploadSize":"53687091200","domain":"driveapis.cloud.huawei.com.cn","category":"drive#about","user":{"permissionId":"239046878371512704","displayName":"*******3121@**3.com","me":true,"category":"drive#user"},"folderLevel":10}
--batch8ffaa9960b344534981a5c7ad7bbda81
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 403 Forbidden
Content-type: application/json
content-length: 305
Content-Length: 305
{"error":{"code":403,"description":"The target folder contains folders with the same name.","errorDetail":[{"reason":"SAME_FILENAME_NOT_ALLOWED","domain":"global","errorCode":"21014932","description":"The target folder contains folders with the same name. ErrorNo:16000-17-1592555387971-305192476-302"}]}}
--batch8ffaa9960b344534981a5c7ad7bbda81
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 200 OK
Content-type: application/json
content-length: 1631
Content-Length: 1631
{"files":[{"id":"AhjIbkluCuoALY1nM1tP43oVjWEzVgrsA","mimeType":"application/vnd.huawei-apps.folder"},{"id":"AhjIVioECuoALY1fUDFP43oVjVlQPArsA","mimeType":"application/vnd.huawei-apps.folder"},{"id":"ABghFaDmCuoCLWQc2tNP43gVZBra3grsA","mimeType":"text/html"},{"id":"ABgKPxq8CuoCLU82YIlP43gVTzBghArsA","mimeType":"application/octet-stream"},{"id":"ABgL5WYKCuoCLU7sHD9P43gVTuocMgrsA","mimeType":"application/octet-stream"},{"id":"ABgIbv7QCuoCLU1nhOVP43gVTWGE6ArsA","mimeType":"text/html"},{"id":"AhgJ8qXgCuoALUz739VP43oVTP3f2ArsA","mimeType":"application/vnd.huawei-apps.folder"},{"id":"AhgJxQhqCuoALUzMcl9P43oVTMpyUgrsA","mimeType":"application/vnd.huawei-apps.folder"},{"id":"ABm5zgyeCuoCLPzHdqtP43gU_MF2pgrsA","mimeType":"application/octet-stream"},{"id":"ABm5tLTwCuoCLPy9zsVP43gU_LvOyArsA","mimeType":"application/octet-stream"},{"id":"ABm5tTQYCuoCLPy8Ti1P43gU_LpOIArsA","mimeType":"application/octet-stream"},{"id":"ABmesGT4CuoCLNu5Hs1P43gU278ewArsA","mimeType":"text/html"},{"id":"AhnuPBT0CuoALKs1bsFP43oUqzNuzArsA","mimeType":"application/vnd.huawei-apps.folder"},{"id":"AhnuIMsECuoALKspsTFP43oUqy-xPArsA","mimeType":"application/vnd.huawei-apps.folder"},{"id":"ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA","mimeType":"text/html"},{"id":"ABnuMIFyCuoCLKs5-0dP43gUqz_7SgrsA","mimeType":"text/html"},{"id":"ABnMxwBgCuoCLInOelVP43gUich6WArsA","mimeType":"text/html"},{"id":"Ah6a-ecaCuoAK9_wnS9P43oT3_adIgrsA","mimeType":"application/vnd.huawei-apps.folder"},{"id":"Ah6a6EJyCuoAK9_hOEdP43oT3-c4SgrsA","mimeType":"application/vnd.huawei-apps.folder"},{"id":"Ah5wjNd8CuoAKzWFrUlP43oTNYOtRArsA","mimeType":"application/vnd.huawei-apps.folder"}]}
--batch8ffaa9960b344534981a5c7ad7bbda81
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 200 OK
Content-type: application/json
content-length: 1849
Content-Length: 1849
{"fileName":"fieldsErrorCopy2","sha256":"495d68028f6866a2771d4faa7b902ba06703ac6b26513c0ff0f6b72988f0a78d","owners":[{"permissionId":"239046878371512704","displayName":"*******3121@**3.com","me":true,"category":"drive#user"}],"hasShared":false,"mimeType":"text/html","lastHistoryVersionId":"ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA","permissions":[{"role":"owner","deleted":false,"displayName":"*******3121@**3.com","id":"239046878371512704","category":"drive#permission","type":"user"}],"occupiedSpace":6199,"createdTime":"2020-05-25T03:31:22.000Z","id":"ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA","ownedByMe":true,"version":1590658150000,"iconDownloadLink":"https://event-dre.dbankcdn.com/filemanagerpic/201911140913476Sc7.png","size":6199,"existThumbnail":false,"containers":["drive"],"favorite":false,"contentVersion":"94840c24-d620-3923-9bb7-6fb33c10a4e2","permissionIds":["239046878371512704"],"parentFolder":["AgFovWXIAIYANC20H_1Fj3oMLbIf8ACAA"],"recycled":false,"directlyRecycled":false,"contentDownloadLink":"https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA?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},"editedTime":"2020-05-25T03:31:22.000Z","thumbnailVersion":0,"lastEditor":{"permissionId":"239046878371512704","displayName":"*******3121@**3.com","me":true,"category":"drive#user"},"category":"drive#file"}
--batch8ffaa9960b344534981a5c7ad7bbda81
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 200 OK
Content-type: application/json
content-length: 1843
Content-Length: 1843
{"fileName":"driveTest2","sha256":"495d68028f6866a2771d4faa7b902ba06703ac6b26513c0ff0f6b72988f0a78d","owners":[{"permissionId":"239046878371512704","displayName":"*******3121@**3.com","me":true,"category":"drive#user"}],"hasShared":false,"mimeType":"text/html","lastHistoryVersionId":"ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA","permissions":[{"role":"owner","deleted":false,"displayName":"*******3121@**3.com","id":"239046878371512704","category":"drive#permission","type":"user"}],"occupiedSpace":6199,"createdTime":"2020-05-25T03:31:22.000Z","id":"ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA","ownedByMe":true,"version":1592555245000,"iconDownloadLink":"https://event-dre.dbankcdn.com/filemanagerpic/201911140913476Sc7.png","size":6199,"existThumbnail":false,"containers":["drive"],"favorite":false,"contentVersion":"94840c24-d620-3923-9bb7-6fb33c10a4e2","permissionIds":["239046878371512704"],"parentFolder":["AgFovWXIAIYANC20H_1Fj3oMLbIf8ACAA"],"recycled":false,"directlyRecycled":false,"contentDownloadLink":"https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA?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},"editedTime":"2020-05-25T03:31:22.000Z","thumbnailVersion":0,"lastEditor":{"permissionId":"239046878371512704","displayName":"*******3121@**3.com","me":true,"category":"drive#user"},"category":"drive#file"}
--batch8ffaa9960b344534981a5c7ad7bbda81-- 错误码后4位为业务错误码,用于区分错误场景,其他业务错误码见状态码章节。
状态码 | 错误码 | 响应代码 | 描述 |
|---|---|---|---|
200 | NA | - | 成功。 |
400 | NA | PARAM_VALUE_NOT_SUPPORT | 参数不支持,请检查参数列表。 |
404 | NA | SERVICE_NOT_FOUND | 服务器无法响应。 |
500 | NA | SERVER_TEMP_ERROR | 服务器内部错误。 |
503 | NA | SERVICE_UNAVAILABLE | 服务不可达。 |
504 | NA | REQUEST_TIMEOUT | 请求超时。 |
public static void main(String[] args) throws IOException {
// 设置请求地址
String url = "https://driveapis.cloud.huawei.com.cn/batch/drive/v3";
// 调用批处理接口
JSONObject fileInfo = batchCallback(url);
System.out.println(fileInfo.toJSONString());
}
private static JSONObject batchCallback(String url) throws IOException {
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "multipart/mixed; boundary=END_OF_PART");
/*
The entity contains six drive requests that are aboutGet, filesCreateMetadata,
filesList, filesGet, filesUpdate and filesDelete.
Before using this entity, you should get accessToken first, and then change it in this entity
*/
StringEntity entity = new StringEntity(
"--END_OF_PART\n" + "Content-Type: application/http\n" + "Content-Transfer-Encoding: binary\n" + "\n"
+ "GET https://driveapis.cloud.huawei.com.cn/drive/v1/about?fields=* \n"
+ "Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du\n"
+ "--END_OF_PART\n" + "Content-Type: application/http\n" + "Content-Transfer-Encoding: binary\n" + "\n"
+ "POST https://driveapis.cloud.huawei.com.cn/drive/v1/files?fields=* \n"
+ "Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du\n"
+ "Content-Type: application/json\n" + "\n" + "{\n" + "\t\"fileName\":\"driveTest1\",\n"
+ "\t\"favorite\":\"true\",\n" + "\t\"description\":\"folder\",\n"
+ "\t\"mimeType\":\"application/vnd.huawei-apps.folder\"\n" + "}\n" + "--END_OF_PART\n"
+ "Content-Type: application/http\n" + "Content-Transfer-Encoding: binary\n" + "\n"
+ "GET https://driveapis.cloud.huawei.com.cn/drive/v1/files?fields=files(id,mimeType) \n"
+ "Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du\n"
+ "Content-Type: application/json\n" + "--END_OF_PART\n" + "Content-Type: application/http\n"
+ "Content-Transfer-Encoding: binary\n" + "\n"
+ "GET https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA?fields=* \n"
+ "Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du\n"
+ "Content-Type: application/json\n" + "--END_OF_PART\n" + "Content-Type: application/http\n"
+ "Content-Transfer-Encoding: binary\n" + "\n"
+ "PATCH https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA?fields=* \n"
+ "Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du\n"
+ "Content-Type: application/json\n" + "\n" + "{\n" + "\t\"fileName\":\"driveTest2\"\n" + "}\n"
+ "--END_OF_PART\n" + "Content-Type: application/http\n" + "Content-Transfer-Encoding: binary\n" + "\n"
+ "DELETE https://driveapis.cloud.huawei.com.cn/drive/v1/files/ABnuTgJyCuoCLKtHeEdP43gUq0F4SgrsA?fields=* \n"
+ "Authorization: Bearer CgB6e3x9Xyu366nn2p+MjHX5JeR6E8r1/w1Vip0P09Evd41mAODnd5W8uW5Q5rK5djpARUV9dqQPT28xab30YvUBFfVNaZUuJ9xJkmsUi3K9dWxV9/du\n"
+ "Content-Type: application/json\n" + "--END_OF_PART--");
httpPost.setEntity(entity);
CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost);
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();
}
}