├── Third Party Open Source Software Notice.docx ├── src └── main │ ├── resources │ └── log4j │ └── java │ └── com │ └── huawei │ └── drive │ └── demo │ ├── files │ ├── FilesEmptyRecycle.java │ ├── FilesDelete.java │ ├── FilesGetContent.java │ ├── FilesGet.java │ ├── FilesList.java │ ├── FilesUpdate.java │ ├── FilesCopy.java │ ├── FilesCreateContent.java │ ├── FilesCreateMetadata.java │ ├── FilesCreateResume.java │ ├── FilesSubscribe.java │ ├── FilesResume.java │ ├── FilesUpdatePutresume.java │ ├── FilesUpdatePatchresume.java │ ├── FilesUpdatePutcontent.java │ ├── FilesUpdatePatchcontent.java │ ├── FilesCreateMultipart.java │ ├── FilesUpdatePutmultipart.java │ └── FilesUpdatePatchmultipart.java │ ├── thumbnail │ └── ThumbnailGet.java │ ├── smallThumbnail │ └── SmallThumbnailGet.java │ ├── comments │ ├── CommentsDelete.java │ ├── CommentsGet.java │ ├── CommentsList.java │ ├── CommentsUpdate.java │ └── CommentsCreate.java │ ├── about │ └── AboutGet.java │ ├── changes │ ├── ChangesGetStartCursor.java │ ├── ChangesList.java │ └── ChangesSubscribe.java │ ├── replies │ ├── RepliesDelete.java │ ├── RepliesGet.java │ ├── RepliesList.java │ ├── RepliesCreate.java │ └── RepliesUpdate.java │ ├── channels │ └── ChannelsStop.java │ └── utils │ └── HttpClientUtil.java ├── pom.xml ├── README_ZH.md ├── README.md └── LICENSE /Third Party Open Source Software Notice.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-drive-serverdemo/HEAD/Third Party Open Source Software Notice.docx -------------------------------------------------------------------------------- /src/main/resources/log4j: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG, file 2 | 3 | log4j.appender.file=org.apache.log4j.RollingFileAppender 4 | log4j.appender.file.File=target/logs/httpClient.log 5 | log4j.appender.file.MaxFileSize=10MB 6 | log4j.appender.file.MaxBackupIndex=1 7 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.huawei.HuaweiDriveSampleResful 8 | HuaweiDriveSampleResful 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | com.alibaba 15 | fastjson 16 | 1.2.62 17 | 18 | 19 | org.apache.httpcomponents 20 | httpclient 21 | 4.5.7 22 | 23 | 24 | org.apache.httpcomponents 25 | httpmime 26 | 4.5.7 27 | 28 | 29 | commons-io 30 | commons-io 31 | 2.6 32 | 33 | 34 | -------------------------------------------------------------------------------- /README_ZH.md: -------------------------------------------------------------------------------- 1 | # HMS Drivekit 服务端示例代码 2 | 中文 | [English](https://github.com/HMS-Core/hms-drive-serverdemo) 3 | ## 目录 4 | 5 | * [简介](#简介) 6 | * [安装](#安装) 7 | * [配置](#配置) 8 | * [环境支持](#环境支持) 9 | * [开始](#开始) 10 | * [License](#license) 11 | 12 | 13 | ## 简介 14 | 15 | 在本示例代码中, 请求及响应通过HTTP客户端实现收发. HUAWEI Drive Kit ("Dive Kit")开放的所有API接口都可以通过本示例代码实现调用。 16 | 注意: Access_token (AT) 需要通过HUAWEI Account Kit获取. 17 | 18 | ## 安装 19 | 在使用HUAWEI Drive Kit服务端示例代码之前, 需要检查JAVA和MAVEN是否已正确安装。 20 | 解压缩HUAWEI Drive Kit服务器示例代码包。 21 | 运行Drive服务端示例代码的步骤如下: 22 | 1. 将项目导入到您的JAVA集成开发环境中。 23 | 2. 使用Maven编译该项目。 24 | 3. 预先获取参数填入每个Java文件的Main函数中。例如,通过HMS Core SDK获得AT。 25 | 更多详情请参见 : [HUAWEI Drive 服务端开发指南](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/server-dev-0000001050039664) 26 | 27 | 28 | ## 环境支持 29 | 建议使用Java 1.8 或者更高版本。 30 | 建议使用Maven 3.6.1版本。 31 | 32 | 33 | ## 配置 34 | 无特殊配置要求。 35 | 36 | ## 开始 37 | 当前华为云空间服务(HUAWEI Drive Kit)的核心能力包括文件的上传、下载和搜索,对文件的评论、回复,云端文件变化的查询、推送通知功能等。 38 | 1. 预先获取参数填入每个Java文件的Main函数中。例如,通过HMS Core SDK获得AT。 39 | 2. 调用接口时,有些接口依赖于其他接口的调用,例如: 40 | 在调用changesSubscribe 和 ChangesList接口之前, 你需要先调用ChangesGetStartCursor获取startCursor。 41 | 在调用ChannelsStop接口之前,你需要创建一个合法的订阅通道。 42 | 在调用FilesResume接口之前, 你需要先调用FilesCreateResume或FilesUpdateResume来获取uploadId和serverId。 43 | 在调用FilesCopy, FilesDelete, FilesGet, FilesUpdate, FilesUpdate*, FilesSubscribe, or FilesGet*等接口之前, 你需要先调用FilesCreate*接口来创建文件或目录并获取fileId。 44 | 45 | ## 技术支持 46 | 如果您对HMS Core还处于评估阶段,可在[Reddit社区](https://www.reddit.com/r/HuaweiDevelopers/)获取关于HMS Core的最新讯息,并与其他开发者交流见解。 47 | 48 | 如果您对使用HMS示例代码有疑问,请尝试: 49 | - 开发过程遇到问题上[Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services),在`huawei-mobile-services`标签下提问,有华为研发专家在线一对一解决您的问题。 50 | - 到[华为开发者论坛](https://developer.huawei.com/consumer/cn/forum/blockdisplay?fid=18) HMS Core板块与其他开发者进行交流。 51 | 52 | 如果您在尝试示例代码中遇到问题,请向仓库提交[issue](https://github.com/HMS-Core/hms-drive-serverdemo/issues),也欢迎您提交[Pull Request](https://github.com/HMS-Core/hms-drive-serverdemo/pulls)。 53 | 54 | ## License 55 | Drivekit 服务端示例代码基于许可 [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). 56 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesEmptyRecycle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.huawei.drive.demo.utils.HttpClientUtil; 20 | import org.apache.http.client.methods.CloseableHttpResponse; 21 | import org.apache.http.client.methods.HttpDelete; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | * 27 | * 28 | * @author drive 29 | * @since 30 | */ 31 | public class FilesEmptyRecycle { 32 | public static void main(String[] args) throws IOException { 33 | 34 | String url = "https://drive.cloud.hicloud.com/drive/v1/files/recycle"; 35 | String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ=="; 36 | 37 | Boolean isTrash = false; 38 | isTrash = filesEmptyTrash(url, access_token); 39 | 40 | System.out.println(isTrash); 41 | } 42 | 43 | private static Boolean filesEmptyTrash(String url, String access_token) throws IOException { 44 | HttpDelete httpDelete = new HttpDelete(url); 45 | httpDelete.setHeader("Authorization","Bearer " + access_token); 46 | 47 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpDelete); 48 | 49 | try { 50 | if(response.getStatusLine().getStatusCode() == 204){//httpStatus 204 stands for success 51 | return true; 52 | } 53 | return false; 54 | }finally { 55 | response.close(); 56 | } 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesDelete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.huawei.drive.demo.utils.HttpClientUtil; 20 | 21 | import org.apache.http.client.methods.CloseableHttpResponse; 22 | import org.apache.http.client.methods.HttpDelete; 23 | 24 | import java.io.IOException; 25 | 26 | /** 27 | * 28 | * 29 | * @author drive 30 | * @since 31 | */ 32 | public class FilesDelete { 33 | public static void main(String[] args) throws IOException { 34 | 35 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 36 | String fileId = "AAAKTnFgAIYCkUs9n_FB9ewNSzuf_ACAA"; 37 | String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ=="; 38 | 39 | Boolean isDelete = false; 40 | isDelete = filesDelete(url, access_token, fileId); 41 | 42 | System.out.println(isDelete); 43 | } 44 | 45 | private static Boolean filesDelete(String url, String access_token, String fileId) throws IOException { 46 | StringBuilder stringBuilder = new StringBuilder(""); 47 | stringBuilder.append("/").append(fileId); 48 | HttpDelete httpDelete = new HttpDelete(url + stringBuilder); 49 | httpDelete.setHeader("Authorization","Bearer " + access_token); 50 | 51 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpDelete); 52 | 53 | try { 54 | if(response.getStatusLine().getStatusCode() == 204){//httpStatus 204 stands for success 55 | return true; 56 | } 57 | return false; 58 | }finally { 59 | response.close(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/thumbnail/ThumbnailGet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.thumbnail; 18 | 19 | import com.huawei.drive.demo.utils.HttpClientUtil; 20 | import org.apache.commons.io.FileUtils; 21 | import org.apache.http.HttpEntity; 22 | import org.apache.http.client.methods.CloseableHttpResponse; 23 | import org.apache.http.client.methods.HttpGet; 24 | 25 | import java.io.File; 26 | import java.io.IOException; 27 | import java.io.InputStream; 28 | 29 | /** 30 | * 31 | * 32 | * @author drive 33 | * @since 34 | */ 35 | public class ThumbnailGet { 36 | public static void main(String[] args) throws IOException { 37 | 38 | String url = "https://drive.cloud.hicloud.com/drive/v1/thumbnails"; 39 | String fileId = "AACUf44uK7wAg6pECq0Vh4QNqkgKoCuwA"; 40 | String access_token = "CF3qHUcDOG3Rq+aCBdoTbdxTQYmIrt1c8xeVvh7Tquare/8VD+7YZFNxzuz5ZdhDrulEWOZVECrpQbVOqVMABeKe9p4wjL4UxskLw7KJKvs0fvZEJqjAKQ=="; 41 | thumbnailGet(url, access_token, fileId); 42 | } 43 | 44 | private static void thumbnailGet(String url, String access_token, String fileId) throws IOException { 45 | StringBuilder stringBuilder = new StringBuilder(""); 46 | stringBuilder.append("/").append(fileId); 47 | stringBuilder.append("?").append("form=content"); 48 | HttpGet httpGet = new HttpGet(url + stringBuilder); 49 | httpGet.setHeader("Authorization","Bearer " + access_token); 50 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 51 | 52 | try { 53 | HttpEntity responseEntity = response.getEntity(); 54 | InputStream inputStream=responseEntity.getContent(); 55 | FileUtils.copyToFile(inputStream, new File("D://thumbnail.jpg")); 56 | }finally { 57 | response.close(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/smallThumbnail/SmallThumbnailGet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.smallThumbnail; 18 | 19 | import com.huawei.drive.demo.utils.HttpClientUtil; 20 | import org.apache.commons.io.FileUtils; 21 | import org.apache.http.HttpEntity; 22 | import org.apache.http.client.methods.CloseableHttpResponse; 23 | import org.apache.http.client.methods.HttpGet; 24 | 25 | import java.io.File; 26 | import java.io.IOException; 27 | import java.io.InputStream; 28 | 29 | /** 30 | * 31 | * 32 | * @author drive 33 | * @since 34 | */ 35 | public class SmallThumbnailGet { 36 | public static void main(String[] args) throws IOException { 37 | 38 | String url = "https://drive.cloud.hicloud.com/drive/v1/smallThumbnails"; 39 | String fileId = "AACUf44uK7wAg6pECq0Vh4QNqkgKoCuwA"; 40 | String access_token = "CF3qHUcDOG3Rq+aCBdoTbdxTQYmIrt1c8xeVvh7Tquare/8VD+7YZFNxzuz5ZdhDrulEWOZVECrpQbVOqVMABeKe9p4wjL4UxskLw7KJKvs0fvZEJqjAKQ=="; 41 | smallThumbnailGet(url, access_token, fileId); 42 | } 43 | 44 | private static void smallThumbnailGet(String url, String access_token, String fileId) throws IOException { 45 | StringBuilder stringBuilder = new StringBuilder(""); 46 | stringBuilder.append("/").append(fileId); 47 | stringBuilder.append("?").append("form=content"); 48 | HttpGet httpGet = new HttpGet(url + stringBuilder); 49 | httpGet.setHeader("Authorization","Bearer " + access_token); 50 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 51 | 52 | try { 53 | HttpEntity responseEntity = response.getEntity(); 54 | InputStream inputStream=responseEntity.getContent(); 55 | FileUtils.copyToFile(inputStream, new File("D://smallThumbnail.jpg")); 56 | }finally { 57 | response.close(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/comments/CommentsDelete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.comments; 18 | 19 | import com.huawei.drive.demo.utils.HttpClientUtil; 20 | import org.apache.http.client.methods.CloseableHttpResponse; 21 | import org.apache.http.client.methods.HttpDelete; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | * 功能描述 27 | * 28 | * @author drive 29 | * @since 30 | */ 31 | public class CommentsDelete { 32 | public static void main(String[] args) throws IOException { 33 | 34 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 35 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 36 | String commentId = "BlIuT9Ue4I8qnKGDcmf9MUZf5sCpjOCDK"; 37 | String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 38 | 39 | Boolean isDelete = false; 40 | isDelete = commentDelete(url, access_token, fileId, commentId); 41 | 42 | System.out.println(isDelete); 43 | } 44 | 45 | private static Boolean commentDelete(String url, String access_token, String fileId, String commentId) throws IOException { 46 | StringBuilder stringBuilder = new StringBuilder(""); 47 | stringBuilder.append("/").append(fileId).append("/").append("comments").append("/").append(commentId); 48 | HttpDelete httpDelete = new HttpDelete(url + stringBuilder); 49 | httpDelete.setHeader("Authorization","Bearer " + access_token); 50 | 51 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpDelete); 52 | 53 | try { 54 | if(response.getStatusLine().getStatusCode() == 204){//httpStatus 204 stands for success 55 | return true; 56 | } 57 | return false; 58 | }finally { 59 | response.close(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/about/AboutGet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.about; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpGet; 25 | import org.apache.http.util.EntityUtils; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * 31 | * 32 | * @author drive 33 | * @since 34 | */ 35 | public class AboutGet { 36 | 37 | public static void main(String[] args) throws IOException{ 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/about"; 40 | String access_token = "CV4HEE3+SNPyFYVNwrpd5SuS0HcP+VMB0EdJR5bNZws3Ek8x9IBbaZ86GuTSSPqhcJGuP0IrGBsNxpY7YdL0C4LVDV6oApIEDYQ62hB+XBujReP2RtXRVw=="; 41 | 42 | JSONObject aboutInfo = aboutGet(url, access_token); 43 | System.out.println(aboutInfo.toJSONString()); 44 | 45 | } 46 | 47 | private static JSONObject aboutGet(String url, String access_token) throws IOException { 48 | StringBuilder stringBuilder = new StringBuilder(""); 49 | stringBuilder.append("?").append("fields=*"); 50 | HttpGet httpGet = new HttpGet(url + stringBuilder); 51 | httpGet.setHeader("Authorization","Bearer " + access_token); 52 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 53 | 54 | try { 55 | HttpEntity responseEntity = response.getEntity(); 56 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 57 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 58 | EntityUtils.consume(responseEntity); 59 | return jsonObject; 60 | }finally { 61 | response.close(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/changes/ChangesGetStartCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.changes; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpGet; 25 | import org.apache.http.util.EntityUtils; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * 31 | * 32 | * @author drive 33 | * @since 34 | */ 35 | public class ChangesGetStartCursor { 36 | public static void main(String[] args) throws IOException { 37 | 38 | String url = "https://drive.cloud.hicloud.com/drive/v1/changes/getStartCursor"; 39 | String access_token = "CV4J+imzJ4fPpQ20ZN6wxBuGx0ncFnfDkXaODQsy5U0QbphRDEkeLneTnwybLVyiGeChaQhiFIdRq75SPD5oIRoTDBGqWE4qLC5FJtjVKL48z6PS4XLH3g=="; 40 | 41 | JSONObject cursorInfo = changesGetStartCursor(url, access_token); 42 | System.out.println(cursorInfo.toJSONString()); 43 | } 44 | 45 | private static JSONObject changesGetStartCursor(String url, String access_token) throws IOException { 46 | StringBuilder stringBuilder = new StringBuilder(""); 47 | stringBuilder.append("?").append("fields=*"); 48 | HttpGet httpGet = new HttpGet(url + stringBuilder); 49 | httpGet.setHeader("Authorization","Bearer " + access_token); 50 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 51 | 52 | try { 53 | HttpEntity responseEntity = response.getEntity(); 54 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 55 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 56 | EntityUtils.consume(responseEntity); 57 | return jsonObject; 58 | }finally { 59 | response.close(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesGetContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.huawei.drive.demo.utils.HttpClientUtil; 20 | import org.apache.commons.io.FileUtils; 21 | import org.apache.http.HttpEntity; 22 | import org.apache.http.client.methods.CloseableHttpResponse; 23 | import org.apache.http.client.methods.HttpGet; 24 | 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class FilesGetContent { 37 | 38 | public static void main(String[] args) throws IOException { 39 | 40 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 41 | String fileId = "AACUf44uK7wAg6pECq0Vh4QNqkgKoCuwA"; 42 | String access_token = "CF3qCeRPLh5GzjpB3ta5UscyjQa2rZhjgFzULNJqVDmCGCJi7IjrQwG7MKmpWIHTq6PRVeYSDsTZtjMbeCoP9ReANeBzHPYRHAppt8HZAaw/3H+IiLbWzQ=="; 43 | filesGetMedia(url, access_token, fileId); 44 | } 45 | 46 | private static void filesGetMedia(String url, String access_token, String fileId) throws IOException { 47 | StringBuilder stringBuilder = new StringBuilder(""); 48 | stringBuilder.append("/").append(fileId); 49 | stringBuilder.append("?").append("form=content"); 50 | HttpGet httpGet = new HttpGet(url + stringBuilder); 51 | httpGet.setHeader("Authorization","Bearer " + access_token); 52 | httpGet.setHeader("Cache-Control","no-cache"); 53 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 54 | 55 | try { 56 | response.setHeader("Content-type","image/jpeg"); 57 | HttpEntity responseEntity = response.getEntity(); 58 | InputStream inputStream=responseEntity.getContent(); 59 | FileUtils.copyToFile(inputStream, new File("D://2.jpg")); 60 | }finally { 61 | response.close(); 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesGet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpGet; 25 | import org.apache.http.util.EntityUtils; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * 31 | * 32 | * @author drive 33 | * @since 34 | */ 35 | public class FilesGet { 36 | public static void main(String[] args) throws IOException { 37 | 38 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 39 | String fileId = "AAAKTnFgAIYCkUs9n_FB9ewNSzuf_ACAA"; 40 | String access_token = "CF3mCevCXcxlfnkkJ+07JEYRgb6x/vVEerMg6zfmk/8X/3ZrZfIuxlAD6U37YdyXxZUjmWnwC64gdnOSMPzZ294fhEFdbBP05h1N+GeHcrEeyPltSPIUvw=="; 41 | 42 | JSONObject fileInfo = filesGet(url, access_token, fileId); 43 | System.out.println(fileInfo.toJSONString()); 44 | } 45 | 46 | private static JSONObject filesGet(String url, String access_token, String fileId) throws IOException { 47 | StringBuilder stringBuilder = new StringBuilder(""); 48 | stringBuilder.append("/").append(fileId); 49 | stringBuilder.append("?").append("fields=*"); 50 | HttpGet httpGet = new HttpGet(url + stringBuilder); 51 | httpGet.setHeader("Authorization","Bearer " + access_token); 52 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 53 | 54 | try { 55 | HttpEntity responseEntity = response.getEntity(); 56 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 57 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 58 | EntityUtils.consume(responseEntity); 59 | return jsonObject; 60 | }finally { 61 | response.close(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/changes/ChangesList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.changes; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpGet; 25 | import org.apache.http.util.EntityUtils; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * 31 | * 32 | * @author drive 33 | * @since 34 | */ 35 | public class ChangesList { 36 | public static void main(String[] args) throws IOException { 37 | 38 | String url = "https://drive.cloud.hicloud.com/drive/v1/changes"; 39 | String cursor = "244021115121339392";//get cursor from ChangesGetStartCursor API 40 | String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ=="; 41 | 42 | JSONObject changesInfo = changesList(url, access_token, cursor); 43 | System.out.println(changesInfo.toJSONString()); 44 | } 45 | 46 | private static JSONObject changesList(String url, String access_token, String cursor) throws IOException { 47 | StringBuilder stringBuilder = new StringBuilder(""); 48 | stringBuilder.append("?").append("fields=*").append("&").append("cursor").append("=").append(cursor); 49 | HttpGet httpGet = new HttpGet(url + stringBuilder); 50 | httpGet.setHeader("Authorization","Bearer " + access_token); 51 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 52 | 53 | try { 54 | HttpEntity responseEntity = response.getEntity(); 55 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 56 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 57 | EntityUtils.consume(responseEntity); 58 | return jsonObject; 59 | }finally { 60 | response.close(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/replies/RepliesDelete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.replies; 18 | 19 | import com.huawei.drive.demo.utils.HttpClientUtil; 20 | import org.apache.http.client.methods.CloseableHttpResponse; 21 | import org.apache.http.client.methods.HttpDelete; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | * 功能描述 27 | * 28 | * @author drive 29 | * @since 30 | */ 31 | public class RepliesDelete { 32 | public static void main(String[] args) throws IOException { 33 | 34 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 35 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 36 | String commentId = "BlIuT9Ue4I8qnKGDcmf9MUZf5sCpjOCDK"; 37 | String replyId = "BiHSWt9a39zTQfFCMylFOWYsGtWjyN_Q0"; 38 | String access_token 39 | = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 40 | 41 | Boolean isDelete = false; 42 | isDelete = replyDelete(url, access_token, fileId, commentId, replyId); 43 | 44 | System.out.println(isDelete); 45 | } 46 | 47 | private static Boolean replyDelete(String url, String access_token, String fileId, String commentId, 48 | String replyId) throws IOException { 49 | StringBuilder stringBuilder = new StringBuilder(""); 50 | stringBuilder.append("/") 51 | .append(fileId) 52 | .append("/") 53 | .append("comments") 54 | .append("/") 55 | .append(commentId) 56 | .append("/") 57 | .append("replies").append("/").append(replyId); 58 | HttpDelete httpDelete = new HttpDelete(url + stringBuilder); 59 | httpDelete.setHeader("Authorization", "Bearer " + access_token); 60 | 61 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpDelete); 62 | 63 | try { 64 | if (response.getStatusLine().getStatusCode() == 204) {//httpStatus 204 stands for success 65 | return true; 66 | } 67 | return false; 68 | } finally { 69 | response.close(); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/comments/CommentsGet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.comments; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpGet; 25 | import org.apache.http.util.EntityUtils; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * 功能描述 31 | * 32 | * @author drive 33 | * @since 34 | */ 35 | public class CommentsGet { 36 | public static void main(String[] args) throws IOException { 37 | 38 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 39 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 40 | String commentId = "BlIuT9Ue4I8qnKGDcmf9MUZf5sCpjOCDK"; 41 | String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 42 | 43 | JSONObject commentInfo = commentGet(url, access_token, fileId, commentId); 44 | System.out.println(commentInfo.toJSONString()); 45 | } 46 | 47 | private static JSONObject commentGet(String url, String access_token, String fileId, String commentId) throws IOException { 48 | StringBuilder stringBuilder = new StringBuilder(""); 49 | stringBuilder.append("/").append(fileId).append("/").append("comments").append("/").append(commentId); 50 | stringBuilder.append("?").append("fields=*"); 51 | HttpGet httpGet = new HttpGet(url + stringBuilder); 52 | httpGet.setHeader("Authorization","Bearer " + access_token); 53 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 54 | 55 | try { 56 | HttpEntity responseEntity = response.getEntity(); 57 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 58 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 59 | EntityUtils.consume(responseEntity); 60 | return jsonObject; 61 | }finally { 62 | response.close(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.config.RequestConfig; 24 | import org.apache.http.client.methods.CloseableHttpResponse; 25 | import org.apache.http.client.methods.HttpGet; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class FilesList { 37 | public static void main(String[] args) throws IOException{ 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 40 | String access_token = "CF3qCeRPLh5GzjpB3ta5UscyjQa2rZhjgFzULNJqVDmCGCJi7IjrQwG7MKmpWIHTq6PRVeYSDsTZtjMbeCoP9ReANeBzHPYRHAppt8HZAaw/3H+IiLbWzQ=="; 41 | 42 | JSONObject fileInfo = filesList(url, access_token); 43 | System.out.println(fileInfo.toJSONString()); 44 | } 45 | 46 | private static JSONObject filesList(String url, String access_token) throws IOException { 47 | StringBuilder stringBuilder = new StringBuilder(""); 48 | stringBuilder.append("?").append("fields=*"); 49 | stringBuilder.append("&").append("prettyPrint=true"); 50 | //stringBuilder.append("&").append("form=json"); 51 | HttpGet httpGet = new HttpGet(url + stringBuilder); 52 | httpGet.setHeader("Authorization","Bearer " + access_token); 53 | RequestConfig requestConfig = RequestConfig.custom() 54 | .setConnectTimeout(50000).setConnectionRequestTimeout(10000) 55 | .setSocketTimeout(50000).build(); 56 | httpGet.setConfig(requestConfig); 57 | 58 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 59 | 60 | 61 | 62 | try { 63 | HttpEntity responseEntity = response.getEntity(); 64 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 65 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 66 | EntityUtils.consume(responseEntity); 67 | return jsonObject; 68 | }finally { 69 | response.close(); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/channels/ChannelsStop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.channels; 18 | 19 | import com.alibaba.fastjson.JSONObject; 20 | import com.huawei.drive.demo.utils.HttpClientUtil; 21 | import org.apache.http.client.methods.CloseableHttpResponse; 22 | import org.apache.http.client.methods.HttpPost; 23 | import org.apache.http.entity.StringEntity; 24 | import java.io.IOException; 25 | 26 | /** 27 | * 28 | * 29 | * @author drive 30 | * @since 31 | */ 32 | public class ChannelsStop { 33 | 34 | public static void main(String[] args) throws IOException { 35 | 36 | String url = "https://drive.cloud.hicloud.com/drive/v1/channels/stop"; 37 | String access_token = "CF3mL4d3n515GWr+NIuuZWwvyInGcUSq7PvN2AYZUnnsrJIArWAuwXLkZB9u4Hlt9gGy8LI4fYk2FXeEMghAUgueN3HblOp+oSbjTcmm0w4I85GbMCCwmg=="; 38 | 39 | Boolean isStop = false; 40 | isStop = channelsStop(url, access_token); 41 | 42 | System.out.println(isStop); 43 | } 44 | 45 | private static Boolean channelsStop(String url, String access_token) throws IOException { 46 | HttpPost httpPost = new HttpPost(url); 47 | httpPost.setHeader("Authorization","Bearer " + access_token); 48 | httpPost.setHeader("Content-Type", "application/json"); 49 | httpPost.setHeader("Accept", "application/json"); 50 | 51 | JSONObject jsonParam = new JSONObject();//You can get every value of jsonParam from ChangesSubscribe 52 | jsonParam.put("resourceId", "MTIzODc5MzU2NTkxNDc5MjMyMA"); 53 | jsonParam.put("category", "api#channel"); 54 | jsonParam.put("expirationTime", "1575363300000"); 55 | jsonParam.put("id", "46TMU"); 56 | jsonParam.put("userToken", "Qeqqn"); 57 | jsonParam.put("type", "web_hook"); 58 | jsonParam.put("url", "https://www.huawei.com"); 59 | jsonParam.put("resourceUri", "https://drive.hicloud.com/drive/v3/changes?pageSize=10&pageToken=244021115121339392&fields=*&alt=json"); 60 | 61 | StringEntity entity = new StringEntity(jsonParam.toString()); 62 | entity.setContentType("application/json"); 63 | httpPost.setEntity(entity); 64 | 65 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 66 | 67 | try { 68 | if(response.getStatusLine().getStatusCode() == 204){ 69 | return true; 70 | } 71 | return false; 72 | }finally { 73 | response.close(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPatch; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class FilesUpdate { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 40 | String fileId = "AgDK9uUMK-YAkYuFC51qle4Ni4MLkCvgA"; 41 | String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ=="; 42 | 43 | JSONObject fileInfo = filesUpdate(url, access_token, fileId); 44 | System.out.println(fileInfo.toJSONString()); 45 | } 46 | 47 | private static JSONObject filesUpdate(String url, String access_token, String fileId) throws IOException { 48 | StringBuilder stringBuilder = new StringBuilder(""); 49 | stringBuilder.append("/").append(fileId); 50 | stringBuilder.append("?").append("fields=*"); 51 | HttpPatch httpPatch = new HttpPatch(url + stringBuilder); 52 | httpPatch.setHeader("Authorization","Bearer " + access_token); 53 | httpPatch.setHeader("Content-Type", "application/json"); 54 | httpPatch.setHeader("Accept", "application/json"); 55 | 56 | JSONObject jsonParam = new JSONObject(); 57 | jsonParam.put("fileName", "HWFile001"); 58 | 59 | StringEntity entity = new StringEntity(jsonParam.toString()); 60 | entity.setContentType("application/json"); 61 | httpPatch.setEntity(entity); 62 | 63 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch); 64 | 65 | try { 66 | HttpEntity responseEntity = response.getEntity(); 67 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 68 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 69 | EntityUtils.consume(responseEntity); 70 | return jsonObject; 71 | }finally { 72 | response.close(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/comments/CommentsList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.comments; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.config.RequestConfig; 24 | import org.apache.http.client.methods.CloseableHttpResponse; 25 | import org.apache.http.client.methods.HttpGet; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 功能描述 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class CommentsList { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 40 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 41 | String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 42 | 43 | JSONObject commentsInfo = commentsList(url, access_token, fileId); 44 | System.out.println(commentsInfo.toJSONString()); 45 | } 46 | 47 | private static JSONObject commentsList(String url, String access_token, String fileId) throws IOException { 48 | StringBuilder stringBuilder = new StringBuilder(""); 49 | stringBuilder.append("/").append(fileId).append("/").append("comments"); 50 | stringBuilder.append("?").append("fields=*"); 51 | stringBuilder.append("&").append("prettyPrint=true"); 52 | //stringBuilder.append("&").append("form=json"); 53 | HttpGet httpGet = new HttpGet(url + stringBuilder); 54 | httpGet.setHeader("Authorization","Bearer " + access_token); 55 | RequestConfig requestConfig = RequestConfig.custom() 56 | .setConnectTimeout(50000).setConnectionRequestTimeout(10000) 57 | .setSocketTimeout(50000).build(); 58 | httpGet.setConfig(requestConfig); 59 | 60 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 61 | 62 | 63 | 64 | try { 65 | HttpEntity responseEntity = response.getEntity(); 66 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 67 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 68 | EntityUtils.consume(responseEntity); 69 | return jsonObject; 70 | }finally { 71 | response.close(); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesCopy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class FilesCopy { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 40 | String fileId = "AAAKRqd2AIYCkUs1SedB9ewNSzNJ6gCAA"; 41 | String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ=="; 42 | 43 | JSONObject fileInfo = filesCopy(url, access_token, fileId); 44 | System.out.println(fileInfo.toJSONString()); 45 | } 46 | 47 | private static JSONObject filesCopy(String url, String access_token, String fileId) throws IOException { 48 | StringBuilder stringBuilder = new StringBuilder(""); 49 | stringBuilder.append("/").append(fileId).append("/").append("copy"); 50 | stringBuilder.append("?").append("fields=*"); 51 | HttpPost httpPost = new HttpPost(url + stringBuilder); 52 | httpPost.setHeader("Authorization","Bearer " + access_token); 53 | httpPost.setHeader("Content-Type", "application/json"); 54 | httpPost.setHeader("Accept", "application/json"); 55 | 56 | JSONObject jsonParam = new JSONObject(); 57 | jsonParam.put("fileName", "HWFileCopy001"); 58 | 59 | StringEntity entity = new StringEntity(jsonParam.toString()); 60 | entity.setContentType("application/json"); 61 | httpPost.setEntity(entity); 62 | 63 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 64 | 65 | try { 66 | HttpEntity responseEntity = response.getEntity(); 67 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 68 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 69 | EntityUtils.consume(responseEntity); 70 | return jsonObject; 71 | }finally { 72 | response.close(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/replies/RepliesGet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.replies; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpGet; 25 | import org.apache.http.util.EntityUtils; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * 功能描述 31 | * 32 | * @author drive 33 | * @since 34 | */ 35 | public class RepliesGet { 36 | public static void main(String[] args) throws IOException { 37 | 38 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 39 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 40 | String commentId = "BlIuT9Ue4I8qnKGDcmf9MUZf5sCpjOCDK"; 41 | String replyId = "BiHSWt9a39zTQfFCMylFOWYsGtWjyN_Q0"; 42 | String access_token 43 | = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 44 | 45 | JSONObject replyInfo = replyGet(url, access_token, fileId, commentId, replyId); 46 | System.out.println(replyInfo.toJSONString()); 47 | } 48 | 49 | private static JSONObject replyGet(String url, String access_token, String fileId, String commentId, String replyId) 50 | throws IOException { 51 | StringBuilder stringBuilder = new StringBuilder(""); 52 | stringBuilder.append("/") 53 | .append(fileId) 54 | .append("/") 55 | .append("comments") 56 | .append("/") 57 | .append(commentId) 58 | .append("/") 59 | .append("replies") 60 | .append("/") 61 | .append(replyId); 62 | stringBuilder.append("?").append("fields=*"); 63 | HttpGet httpGet = new HttpGet(url + stringBuilder); 64 | httpGet.setHeader("Authorization", "Bearer " + access_token); 65 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 66 | 67 | try { 68 | HttpEntity responseEntity = response.getEntity(); 69 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 70 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 71 | EntityUtils.consume(responseEntity); 72 | return jsonObject; 73 | } finally { 74 | response.close(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesCreateContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.entity.FileEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.File; 29 | 30 | import java.io.IOException; 31 | 32 | /** 33 | * 34 | * 35 | * @author drive 36 | * @since 37 | */ 38 | public class FilesCreateContent { 39 | public static void main(String[] args) throws IOException { 40 | 41 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1/files"; 42 | String access_token = "CV4EG6VAnvL8ILp2NsM/fLJNjjLXRxUsljMZnFmH3iuAyIO0n/o0ZS9JC69YF0eUyDgFLX9q4k4+qhacuEvmrGiXMSMnhWvK965gnEUb2ATXLgJ269beh5VNdwYJKNIN2+0="; 43 | 44 | JSONObject fileInfo = filesCreateContent(url, access_token); 45 | System.out.println(fileInfo.toJSONString()); 46 | } 47 | 48 | private static JSONObject filesCreateContent(String url, String access_token) throws IOException { 49 | StringBuilder stringBuilder = new StringBuilder(""); 50 | stringBuilder.append("?").append("fields=*").append("&").append("uploadType=content"); 51 | HttpPost httpPost = new HttpPost(url + stringBuilder); 52 | httpPost.setHeader("Authorization","Bearer " + access_token); 53 | httpPost.setHeader("Content-Type", "image/jpeg"); 54 | httpPost.setHeader("Accept", "application/json"); 55 | 56 | File file = new File("C:\\Users\\z00502234\\Pictures\\Saved Pictures\\8.jpg");//The path of your local file 57 | if(!file.exists()){ 58 | System.out.print("File not exist"); 59 | return null; 60 | } 61 | HttpEntity entity = new FileEntity(file); 62 | httpPost.setEntity(entity); 63 | 64 | 65 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 66 | 67 | try { 68 | HttpEntity responseEntity = response.getEntity(); 69 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 70 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 71 | EntityUtils.consume(responseEntity); 72 | return jsonObject; 73 | }finally { 74 | response.close(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesCreateMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | class FilesCreateMetadata { 37 | 38 | public static void main(String[] args) throws IOException { 39 | 40 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 41 | String access_token = "CV4Js+Z/i4U5W9kSoghQA5//o4orkhDLT55++P895MMHqMhNjCv66x3Ti1bhNvSxaueLBQat2Uh9yLRVdrMjwgdmK4ZkrkaPlQD2xoQh7zl1F5woM+LnHQ=="; 42 | 43 | JSONObject folderInfo = filesCreateMetadata(url, access_token); 44 | System.out.println(folderInfo.toJSONString()); 45 | } 46 | 47 | private static JSONObject filesCreateMetadata(String url, String access_token) throws IOException { 48 | StringBuilder stringBuilder = new StringBuilder(""); 49 | stringBuilder.append("?").append("fields=*"); 50 | HttpPost httpPost = new HttpPost(url + stringBuilder); 51 | httpPost.setHeader("Authorization","Bearer " + access_token); 52 | httpPost.setHeader("Content-Type", "application/json"); 53 | httpPost.setHeader("Accept", "application/json"); 54 | 55 | JSONObject jsonParam = new JSONObject(); 56 | jsonParam.put("fileName", "HWTest1001"); 57 | jsonParam.put("favorite","true");//optional 58 | jsonParam.put("description","folder");//optional 59 | jsonParam.put("mimeType","application/vnd.huawei-apps.folder"); 60 | StringEntity entity = new StringEntity(jsonParam.toString()); 61 | entity.setContentType("application/json"); 62 | httpPost.setEntity(entity); 63 | 64 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 65 | 66 | try { 67 | HttpEntity responseEntity = response.getEntity(); 68 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 69 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 70 | EntityUtils.consume(responseEntity); 71 | return jsonObject; 72 | }finally { 73 | response.close(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/replies/RepliesList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.replies; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.config.RequestConfig; 24 | import org.apache.http.client.methods.CloseableHttpResponse; 25 | import org.apache.http.client.methods.HttpGet; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 功能描述 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class RepliesList { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 40 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 41 | String commentId = "BlIuT9Ue4I8qnKGDcmf9MUZf5sCpjOCDK"; 42 | String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 43 | 44 | JSONObject replyInfo = repliesList(url, access_token, fileId, commentId); 45 | System.out.println(replyInfo.toJSONString()); 46 | } 47 | 48 | private static JSONObject repliesList(String url, String access_token, String fileId, String commentId) throws IOException { 49 | StringBuilder stringBuilder = new StringBuilder(""); 50 | stringBuilder.append("/").append(fileId).append("/").append("comments").append("/").append(commentId).append("/").append("replies"); 51 | stringBuilder.append("?").append("fields=*"); 52 | stringBuilder.append("&").append("prettyPrint=true"); 53 | //stringBuilder.append("&").append("form=json"); 54 | HttpGet httpGet = new HttpGet(url + stringBuilder); 55 | httpGet.setHeader("Authorization","Bearer " + access_token); 56 | RequestConfig requestConfig = RequestConfig.custom() 57 | .setConnectTimeout(50000).setConnectionRequestTimeout(10000) 58 | .setSocketTimeout(50000).build(); 59 | httpGet.setConfig(requestConfig); 60 | 61 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); 62 | 63 | 64 | 65 | try { 66 | HttpEntity responseEntity = response.getEntity(); 67 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 68 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 69 | EntityUtils.consume(responseEntity); 70 | return jsonObject; 71 | }finally { 72 | response.close(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/comments/CommentsUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.comments; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPatch; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 功能描述 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class CommentsUpdate { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 40 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 41 | String commentId = "BlIuT9Ue4I8qnKGDcmf9MUZf5sCpjOCDK"; 42 | String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 43 | 44 | JSONObject commentInfo = commentsUpdate(url, access_token, fileId, commentId); 45 | System.out.println(commentInfo.toJSONString()); 46 | } 47 | 48 | private static JSONObject commentsUpdate(String url, String access_token, String fileId, String commentId) throws IOException { 49 | StringBuilder stringBuilder = new StringBuilder(""); 50 | stringBuilder.append("/").append(fileId).append("/").append("comments").append("/").append(commentId); 51 | stringBuilder.append("?").append("fields=*"); 52 | HttpPatch httpPatch = new HttpPatch(url + stringBuilder); 53 | httpPatch.setHeader("Authorization","Bearer " + access_token); 54 | httpPatch.setHeader("Content-Type", "application/json"); 55 | httpPatch.setHeader("Accept", "application/json"); 56 | 57 | JSONObject jsonParam = new JSONObject(); 58 | jsonParam.put("description", "2020/02/25 11:20"); 59 | 60 | StringEntity entity = new StringEntity(jsonParam.toString()); 61 | entity.setContentType("application/json"); 62 | httpPatch.setEntity(entity); 63 | 64 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch); 65 | 66 | try { 67 | HttpEntity responseEntity = response.getEntity(); 68 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 69 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 70 | EntityUtils.consume(responseEntity); 71 | return jsonObject; 72 | }finally { 73 | response.close(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/replies/RepliesCreate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.replies; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 功能描述 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class RepliesCreate { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files/"; 40 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 41 | String commentId = "BlIuT9Ue4I8qnKGDcmf9MUZf5sCpjOCDK"; 42 | String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 43 | 44 | JSONObject replyInfo = replyCreate(url, access_token, fileId, commentId); 45 | System.out.println(replyInfo.toJSONString()); 46 | } 47 | 48 | private static JSONObject replyCreate(String url, String access_token, String fileId, String commentId) throws IOException { 49 | StringBuilder stringBuilder = new StringBuilder(""); 50 | stringBuilder.append(fileId).append("/").append("comments").append("/").append(commentId).append("/").append("replies"); 51 | stringBuilder.append("?").append("fields=*"); 52 | HttpPost httpPost = new HttpPost(url + stringBuilder); 53 | httpPost.setHeader("Authorization","Bearer " + access_token); 54 | httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); 55 | httpPost.setHeader("Accept", "application/json"); 56 | 57 | JSONObject jsonParam = new JSONObject(); 58 | jsonParam.put("description", "HuaweiTest001"); 59 | jsonParam.put("operate", "reopen"); 60 | 61 | StringEntity entity = new StringEntity(jsonParam.toString()); 62 | httpPost.setEntity(entity); 63 | 64 | 65 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 66 | 67 | try { 68 | HttpEntity responseEntity = response.getEntity(); 69 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 70 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 71 | EntityUtils.consume(responseEntity); 72 | return jsonObject; 73 | }finally { 74 | response.close(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/comments/CommentsCreate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.comments; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 功能描述 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class CommentsCreate { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files/"; 40 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 41 | String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 42 | 43 | JSONObject commentInfo = commentCreateContent(url, access_token, fileId); 44 | System.out.println(commentInfo.toJSONString()); 45 | } 46 | 47 | private static JSONObject commentCreateContent(String url, String access_token, String fileId) throws IOException { 48 | StringBuilder stringBuilder = new StringBuilder(""); 49 | stringBuilder.append(fileId).append("/").append("comments"); 50 | stringBuilder.append("?").append("fields=*"); 51 | HttpPost httpPost = new HttpPost(url + stringBuilder); 52 | httpPost.setHeader("Authorization", "Bearer " + access_token); 53 | httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); 54 | httpPost.setHeader("Accept", "application/json"); 55 | 56 | JSONObject jsonParam = new JSONObject(); 57 | jsonParam.put("description", "2020/02/23 11:20"); 58 | JSONObject jsonObject = new JSONObject(); 59 | jsonObject.put("mimeType", "text/html"); 60 | jsonObject.put("content", "2222"); 61 | jsonParam.put("quotedContent", jsonObject); 62 | 63 | StringEntity entity = new StringEntity(jsonParam.toString()); 64 | httpPost.setEntity(entity); 65 | 66 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 67 | 68 | try { 69 | HttpEntity responseEntity = response.getEntity(); 70 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 71 | JSONObject jsonObject1 = (JSONObject) JSON.parse(ret); 72 | EntityUtils.consume(responseEntity); 73 | return jsonObject1; 74 | } finally { 75 | response.close(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesCreateResume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class FilesCreateResume { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1/files"; 40 | String access_token = "CF3pvqiyaVUXfclpdiztAQIRcW/gGlZzV0HAiJBRe4ClGDYseeS6/PA2FMdMvfSc1vMKwzKJn0ZNPQZglHbpjQvscQA8yj0wmlMz2lhESZoa+pruIHCYQw=="; 41 | 42 | String fileInfo = filesCreateResume(url, access_token); 43 | if(fileInfo != null){ 44 | System.out.println(fileInfo); 45 | } 46 | } 47 | 48 | private static String filesCreateResume(String url, String access_token) throws IOException { 49 | StringBuilder stringBuilder = new StringBuilder(""); 50 | stringBuilder.append("?").append("fields=*"); 51 | stringBuilder.append("&").append("uploadType=resume"); 52 | HttpPost httpPost = new HttpPost(url + stringBuilder); 53 | httpPost.setHeader("Authorization","Bearer " + access_token); 54 | httpPost.setHeader("Content-Type", "application/json;charset=UTF-8"); 55 | httpPost.setHeader("Accept", "application/json"); 56 | //httpPost.setHeader("X-Upload-Content-Type", "image/jpeg"); 57 | httpPost.setHeader("X-Upload-Content-Length", "8023"); 58 | 59 | JSONObject jsonParam = new JSONObject(); 60 | jsonParam.put("fileName", "HWTest001"); 61 | StringEntity entity = new StringEntity(jsonParam.toString()); 62 | entity.setContentType("application/json"); 63 | httpPost.setEntity(entity); 64 | 65 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 66 | 67 | try { 68 | if(response.getStatusLine().getStatusCode() == 200){ 69 | String ret = response.getHeaders("Location")[0].getValue(); 70 | return ret; 71 | } 72 | HttpEntity responseEntity = response.getEntity(); 73 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 74 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 75 | EntityUtils.consume(responseEntity); 76 | return jsonObject.toJSONString(); 77 | }finally { 78 | response.close(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesSubscribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class FilesSubscribe { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 40 | String fileId = "AAAKRqd2AIYCkUs1SedB9ewNSzNJ6gCAA"; 41 | String access_token = "CF3mIRW1G2Ljt8qvDpZuNW0d6lNHXNT4V61o3/XLHIbcI54AQSc8wx2XAuMvOFEFFIwIvWjGitFRV3UCXWiUnuzCx0b5x/4Pq31BJpo4HK46G8l+k2DuEQ=="; 42 | 43 | JSONObject fileInfo = filesSubscribe(url, access_token, fileId); 44 | System.out.println(fileInfo.toJSONString()); 45 | } 46 | 47 | private static JSONObject filesSubscribe(String url, String access_token, String fileId) throws IOException { 48 | StringBuilder stringBuilder = new StringBuilder(""); 49 | stringBuilder.append("/").append(fileId).append("/").append("subscribe"); 50 | stringBuilder.append("?").append("fields=*"); 51 | HttpPost httpPost = new HttpPost(url + stringBuilder); 52 | httpPost.setHeader("Authorization","Bearer " + access_token); 53 | httpPost.setHeader("Content-Type", "application/json"); 54 | httpPost.setHeader("Accept", "application/json"); 55 | 56 | JSONObject jsonParam = new JSONObject(); 57 | jsonParam.put("id", "101207111"); 58 | jsonParam.put("type", "web_hook");//default value 59 | jsonParam.put("userToken", "F0Ge56"); 60 | jsonParam.put("url", "https://www.huawei.com");//Only accept https 61 | //jsonParam.put("expirationTime", "1575362100000");//optional.You can set it in 0-1 day,or use default value.Unix Time 62 | 63 | StringEntity entity = new StringEntity(jsonParam.toString()); 64 | entity.setContentType("application/json"); 65 | httpPost.setEntity(entity); 66 | 67 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 68 | 69 | try { 70 | HttpEntity responseEntity = response.getEntity(); 71 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 72 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 73 | EntityUtils.consume(responseEntity); 74 | return jsonObject; 75 | }finally { 76 | response.close(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesResume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPut; 25 | import org.apache.http.entity.FileEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.File; 29 | import java.io.IOException; 30 | 31 | /** 32 | * 33 | * 34 | * @author drive 35 | * @since 36 | */ 37 | public class FilesResume { 38 | public static void main(String[] args) throws IOException { 39 | 40 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1"; 41 | String serverId = "fc7300dbe0280d39"; 42 | String upload_id = "246009705515379712"; 43 | String access_token = "CF3pvqiyaVUXfclpdiztAQIRcW/gGlZzV0HAiJBRe4ClGDYseeS6/PA2FMdMvfSc1vMKwzKJn0ZNPQZglHbpjQvscQA8yj0wmlMz2lhESZoa+pruIHCYQw=="; 44 | 45 | JSONObject fileInfo = filesResume(url, access_token, serverId, upload_id); 46 | System.out.println(fileInfo.toJSONString()); 47 | } 48 | 49 | 50 | private static JSONObject filesResume(String url, String access_token, String serverId, String upload_id) throws IOException { 51 | StringBuilder stringBuilder = new StringBuilder(""); 52 | stringBuilder.append("/").append(serverId).append("/").append("files"); 53 | stringBuilder.append("?").append("fields=*"); 54 | stringBuilder.append("&").append("uploadType=resume"); 55 | stringBuilder.append("&").append("uploadId=").append(upload_id); 56 | HttpPut httpPut = new HttpPut(url + stringBuilder); 57 | httpPut.setHeader("Authorization","Bearer " + access_token); 58 | httpPut.setHeader("Content-Type", "application/json;charset=UTF-8"); 59 | httpPut.setHeader("Content-Range", "bytes 0-8022/8023"); 60 | 61 | File file = new File("C:\\Users\\z00502234\\Pictures\\Saved Pictures\\2.jpg"); 62 | if(!file.exists()){ 63 | System.out.print("File not exist"); 64 | return null; 65 | } 66 | 67 | HttpEntity entity = new FileEntity(file); 68 | 69 | httpPut.setEntity(entity); 70 | 71 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPut); 72 | 73 | try { 74 | HttpEntity responseEntity = response.getEntity(); 75 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 76 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 77 | EntityUtils.consume(responseEntity); 78 | return jsonObject; 79 | 80 | }finally { 81 | response.close(); 82 | } 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HMS Drivekit Serverdemo 2 | English | [中文](https://github.com/HMS-Core/hms-drive-serverdemo/blob/master/README_ZH.md) 3 | ## Table of Contents 4 | 5 | * [Introduction](#introduction) 6 | * [Installation](#installation) 7 | * [Configuration ](#configuration ) 8 | * [Supported Environments](#supported-environments) 9 | * [Getting Started](#getting-started) 10 | * [License](#license) 11 | 12 | 13 | ## Introduction 14 | 15 | In this demo, requests/responses are sent/received by using the HTTP client. All open APIs provided by HUAWEI Drive Kit ("Dive Kit") can be accessed by this demo. 16 | Note: Access_token (AT) needs to be obtained by using HUAWEI Account Kit. 17 | 18 | ## Installation 19 | Before using HUAWEI Drive Kit Server sample code, check whether the JAVA and Maven environment has been installed. 20 | Decompress the HUAWEI Drive Kit Server sample code package. 21 | The steps to run the Drive service sample code are as follows: 22 | 1. Import project to your JAVA Integrated Development Environment. 23 | 2. Use Maven to compile this project. 24 | 3. Obtain parameters in the Main function of each Java file in advance. For example, obtain the AT through the HMS SDK. 25 | See details : [HUAWEI Drive Service Development Preparation](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/server-dev-0000001050039664) 26 | 27 | 28 | ## Supported Environments 29 | Java 1.8 or a later version is recommended. 30 | Maven 3.6.1 is recommended. 31 | 32 | 33 | ## Configuration 34 | No additional configuration is required. 35 | 36 | ## Getting Started 37 | Currently, the core capabilities of Drive Kit include uploading, downloading, deleting, recycling, and searching for files in Drive as well as querying and monitoring file changes. 38 | 1. Obtain parameters in the Main function of each Java file in advance. For example, obtain the AT through the HMS SDK. 39 | 2. Call the required APIs. Some APIs depend on each other, for example: 40 | Before calling changesSubscribe and ChangesList, you need to call ChangesGetStartCursor to get the query parameter startCursor. 41 | Before calling ChannelsStop, you need to create a valid channel for Watch. 42 | Before calling FilesResume, call FilesCreateResume or FilesUpdateResume to obtain uploadId and serverId. 43 | Before calling FilesCopy, FilesDelete, FilesGet, FilesUpdate, FilesUpdate*, FilesSubscribe, or FilesGet*, you need to call FilesCreate* to create a file and get fileId. 44 | 45 | ## Question or issues 46 | If you want to evaluate more about HMS Core, 47 | [r/HMSCore on Reddit](https://www.reddit.com/r/HuaweiDevelopers/ 48 | ) is for you to keep up with latest news about HMS Core, and to exchange insights with other developers. 49 | 50 | If you have questions about how to use HMS samples, try the following options: 51 | - [Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services) is the best place for any programming questions. Be sure to tag your question with 52 | `huawei-mobile-services`. 53 | - [Huawei Developer Forum](https://forums.developer.huawei.com/forumPortal/en/home?fid=0101187876626530001) HMS Core Module is great for general questions, or seeking recommendations and opinions. 54 | 55 | If you run into a bug in our samples, please submit an [issue](https://github.com/HMS-Core/hms-drive-serverdemo/issues) to the Repository. Even better you can submit a [Pull Request](https://github.com/HMS-Core/hms-drive-serverdemo/pulls) with a fix. 56 | 57 | ## License 58 | Drivekit server Java sample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). 59 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/changes/ChangesSubscribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.changes; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class ChangesSubscribe { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/changes/subscribe"; 40 | String cursor = "263696633739381760";//get cursor from ChangesGetStartCursor API 41 | String access_token = "CV4J+imzJ4fPpQ20ZN6wxBuGx0ncFnfDkXaODQsy5U0QbphRDEkeLneTnwybLVyiGeChaQhiFIdRq75SPD5oIRoTDBGqWE4qLC5FJtjVKL48z6PS4XLH3g=="; 42 | 43 | JSONObject changesInfo = changesSubscribe(url, access_token, cursor); 44 | System.out.println(changesInfo.toJSONString()); 45 | } 46 | 47 | private static JSONObject changesSubscribe(String url, String access_token, String cursor) throws IOException { 48 | StringBuilder stringBuilder = new StringBuilder(""); 49 | stringBuilder.append("?").append("fields=*").append("&").append("cursor").append("=").append(cursor); 50 | HttpPost httpPost = new HttpPost(url + stringBuilder); 51 | httpPost.setHeader("Authorization","Bearer " + access_token); 52 | httpPost.setHeader("Content-Type", "application/json"); 53 | httpPost.setHeader("Accept", "application/json"); 54 | 55 | JSONObject jsonParam = new JSONObject(); 56 | jsonParam.put("id", "46TMU"); 57 | jsonParam.put("type", "web_hook");//default value,can't change 58 | jsonParam.put("userToken", "Qeqqn"); 59 | jsonParam.put("url", "https://www.huawei.com");//Only support https. 60 | //jsonParam.put("expirationTime", "1575363300000");//optional.You can set it in 1-7 day or use default.Unix Time 61 | 62 | StringEntity entity = new StringEntity(jsonParam.toString()); 63 | entity.setContentType("application/json"); 64 | httpPost.setEntity(entity); 65 | 66 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 67 | 68 | try { 69 | HttpEntity responseEntity = response.getEntity(); 70 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 71 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 72 | EntityUtils.consume(responseEntity); 73 | return jsonObject; 74 | }finally { 75 | response.close(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesUpdatePutresume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPut; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class FilesUpdatePutresume { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1/files"; 40 | String fileId = "AACWO19qK7wAg6gA2-kVh4QNqAzb5CuwA"; 41 | String access_token = "CF3p+5TNdpCs0OjI+bP04rVLLe6WJpFWefKlASOzIaDArxxS36ku2TePpHUGzfJAW4C4YO06wB7eIhMdu/MEOsqAkWu0rpNmVcTUsVefUSmt5RUvhAr2oQ=="; 42 | 43 | String fileInfo = filesUpdatePutresume(url, access_token, fileId); 44 | if(fileInfo != null){ 45 | System.out.println(fileInfo); 46 | } 47 | } 48 | 49 | private static String filesUpdatePutresume(String url, String access_token, String fileId) throws IOException { 50 | StringBuilder stringBuilder = new StringBuilder(""); 51 | stringBuilder.append("/").append(fileId); 52 | stringBuilder.append("?").append("fields=").append("*"); 53 | stringBuilder.append("&").append("uploadType=resume"); 54 | HttpPut httpPut = new HttpPut(url + stringBuilder); 55 | httpPut.setHeader("Authorization","Bearer " + access_token); 56 | httpPut.setHeader("Content-Type", "application/json;charset=UTF-8"); 57 | httpPut.setHeader("Accept", "*/*"); 58 | httpPut.setHeader("X-Upload-Content-Length", "49"); 59 | 60 | JSONObject jsonParam = new JSONObject(); 61 | 62 | jsonParam.put("\"appSettings\"", "{ \"test2\": \"value1\" }"); 63 | StringEntity entity = new StringEntity(jsonParam.toString()); 64 | httpPut.setEntity(entity); 65 | 66 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPut); 67 | 68 | try { 69 | if(response.getStatusLine().getStatusCode() == 200){ 70 | String ret = response.getHeaders("Location")[0].getValue(); 71 | return ret; 72 | } 73 | HttpEntity responseEntity = response.getEntity(); 74 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 75 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 76 | EntityUtils.consume(responseEntity); 77 | return jsonObject.toJSONString(); 78 | }finally { 79 | response.close(); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesUpdatePatchresume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPatch; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class FilesUpdatePatchresume { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1/files"; 40 | String fileId = "AACWO19qK7wAg6gA2-kVh4QNqAzb5CuwA"; 41 | String access_token = "CF3p+5TNdpCs0OjI+bP04rVLLe6WJpFWefKlASOzIaDArxxS36ku2TePpHUGzfJAW4C4YO06wB7eIhMdu/MEOsqAkWu0rpNmVcTUsVefUSmt5RUvhAr2oQ=="; 42 | 43 | String fileInfo = filesUpdatePatchresume(url, access_token, fileId); 44 | if(fileInfo != null){ 45 | System.out.println(fileInfo); 46 | } 47 | } 48 | 49 | private static String filesUpdatePatchresume(String url, String access_token, String fileId) throws IOException { 50 | StringBuilder stringBuilder = new StringBuilder(""); 51 | stringBuilder.append("/").append(fileId); 52 | stringBuilder.append("?").append("fields=*"); 53 | stringBuilder.append("&").append("uploadType=resume"); 54 | HttpPatch httpPatch = new HttpPatch(url + stringBuilder); 55 | httpPatch.setHeader("Authorization","Bearer " + access_token); 56 | httpPatch.setHeader("Content-Type", "application/json;charset=UTF-8"); 57 | httpPatch.setHeader("Accept", "*/*"); 58 | httpPatch.setHeader("X-Upload-Content-Length", "53"); 59 | 60 | JSONObject jsonParam = new JSONObject(); 61 | jsonParam.put("\"appSettings\"", "{ \"test1\": \"value1\" }"); 62 | StringEntity entity = new StringEntity(jsonParam.toString()); 63 | httpPatch.setEntity(entity); 64 | 65 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch); 66 | 67 | try { 68 | if(response.getStatusLine().getStatusCode() == 200){ 69 | String ret = response.getHeaders("Location")[0].getValue(); 70 | return ret; 71 | } 72 | HttpEntity responseEntity = response.getEntity(); 73 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 74 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 75 | EntityUtils.consume(responseEntity); 76 | return jsonObject.toJSONString(); 77 | }finally { 78 | response.close(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/replies/RepliesUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.replies; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPatch; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * 功能描述 32 | * 33 | * @author drive 34 | * @since 35 | */ 36 | public class RepliesUpdate { 37 | public static void main(String[] args) throws IOException { 38 | 39 | String url = "https://drive.cloud.hicloud.com/drive/v1/files"; 40 | String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A"; 41 | String commentId = "BlIuT9Ue4I8qnKGDcmf9MUZf5sCpjOCDK"; 42 | String replyId = "BiHSWt9a39zTQfFCMylFOWYsGtWjyN_Q0"; 43 | String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ=="; 44 | 45 | JSONObject replyInfo = replyUpdate(url, access_token, fileId, commentId, replyId); 46 | System.out.println(replyInfo.toJSONString()); 47 | } 48 | 49 | private static JSONObject replyUpdate(String url, String access_token, String fileId, String commentId, 50 | String replyId) throws IOException { 51 | StringBuilder stringBuilder = new StringBuilder(""); 52 | stringBuilder.append("/") 53 | .append(fileId) 54 | .append("/") 55 | .append("comments") 56 | .append("/") 57 | .append(commentId) 58 | .append("/") 59 | .append("replies").append("/").append(replyId); 60 | stringBuilder.append("?").append("fields=*"); 61 | HttpPatch httpPatch = new HttpPatch(url + stringBuilder); 62 | httpPatch.setHeader("Authorization", "Bearer " + access_token); 63 | httpPatch.setHeader("Content-Type", "application/json"); 64 | httpPatch.setHeader("Accept", "application/json"); 65 | 66 | JSONObject jsonParam = new JSONObject(); 67 | jsonParam.put("description", "2020/02/26 11:20"); 68 | 69 | StringEntity entity = new StringEntity(jsonParam.toString()); 70 | entity.setContentType("application/json"); 71 | httpPatch.setEntity(entity); 72 | 73 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch); 74 | 75 | try { 76 | HttpEntity responseEntity = response.getEntity(); 77 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 78 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 79 | EntityUtils.consume(responseEntity); 80 | return jsonObject; 81 | } finally { 82 | response.close(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesUpdatePutcontent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.Consts; 23 | import org.apache.http.HttpEntity; 24 | import org.apache.http.client.config.RequestConfig; 25 | import org.apache.http.client.methods.CloseableHttpResponse; 26 | import org.apache.http.client.methods.HttpPut; 27 | import org.apache.http.entity.ContentType; 28 | import org.apache.http.entity.mime.MultipartEntityBuilder; 29 | import org.apache.http.entity.mime.content.FileBody; 30 | import org.apache.http.util.EntityUtils; 31 | 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.nio.charset.Charset; 35 | 36 | /** 37 | * 38 | * 39 | * @author drive 40 | * @since 41 | */ 42 | public class FilesUpdatePutcontent { 43 | public static void main(String[] args) throws IOException { 44 | 45 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1/files"; 46 | String fileId = "AACeJVrcK7wAg6Ae3l8Vh4QNoBLeUiuwA"; 47 | String access_token = "CF3pA9N/bBr1lFcpPsK7v1W9gtIScpAxfsR0VDiTsCj8TIZwQG4yGBaTYHTQgxVXoVcYgXw+hAhMTE904csrrkQ6v7+RhRm8C6yIEOnDi3YteB3bvyj40w=="; 48 | 49 | JSONObject fileInfo = filesUpdatePutcontent(url, access_token, fileId); 50 | System.out.println(fileInfo.toJSONString()); 51 | } 52 | 53 | private static JSONObject filesUpdatePutcontent(String url, String access_token, String fileId) throws IOException { 54 | StringBuilder stringBuilder = new StringBuilder(""); 55 | stringBuilder.append("/").append(fileId); 56 | stringBuilder.append("?").append("fields=*"); 57 | stringBuilder.append("&").append("uploadType=content"); 58 | HttpPut httpPut = new HttpPut(url + stringBuilder); 59 | httpPut.setHeader("Authorization","Bearer " + access_token); 60 | httpPut.setHeader("Content-Type", "image/jpeg"); 61 | httpPut.setHeader("Accept", "application/json"); 62 | httpPut.setHeader("X-Upload-Content-Type", "image/jpeg"); 63 | 64 | File file = new File("C:\\Users\\z00502234\\Pictures\\Saved Pictures\\5.jpg"); 65 | if(!file.exists()){ 66 | System.out.print("File not exist"); 67 | return null; 68 | } 69 | FileBody bin = new FileBody(file, ContentType.create("image/jpeg", Consts.UTF_8)); 70 | HttpEntity entity = MultipartEntityBuilder 71 | .create() 72 | .setCharset(Charset.forName("utf-8")) 73 | .addPart("file", bin) 74 | .build(); 75 | httpPut.setEntity(entity); 76 | RequestConfig requestConfig = RequestConfig.custom() 77 | .setConnectTimeout(50000).setConnectionRequestTimeout(10000) 78 | .setSocketTimeout(50000).build();//set connection time 79 | httpPut.setConfig(requestConfig); 80 | 81 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPut); 82 | 83 | try { 84 | HttpEntity responseEntity = response.getEntity(); 85 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 86 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 87 | EntityUtils.consume(responseEntity); 88 | return jsonObject; 89 | }finally { 90 | response.close(); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesUpdatePatchcontent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.Consts; 23 | import org.apache.http.HttpEntity; 24 | import org.apache.http.client.config.RequestConfig; 25 | import org.apache.http.client.methods.CloseableHttpResponse; 26 | import org.apache.http.client.methods.HttpPatch; 27 | import org.apache.http.entity.ContentType; 28 | import org.apache.http.entity.mime.MultipartEntityBuilder; 29 | import org.apache.http.entity.mime.content.FileBody; 30 | import org.apache.http.util.EntityUtils; 31 | 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.nio.charset.Charset; 35 | 36 | /** 37 | * 38 | * 39 | * @author drive 40 | * @since 41 | */ 42 | public class FilesUpdatePatchcontent { 43 | public static void main(String[] args) throws IOException { 44 | 45 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1/files"; 46 | String fileId = "AACeJVrcK7wAg6Ae3l8Vh4QNoBLeUiuwA"; 47 | String access_token = "CF3pA9N/bBr1lFcpPsK7v1W9gtIScpAxfsR0VDiTsCj8TIZwQG4yGBaTYHTQgxVXoVcYgXw+hAhMTE904csrrkQ6v7+RhRm8C6yIEOnDi3YteB3bvyj40w=="; 48 | 49 | JSONObject fileInfo = filesUpdatePatchcontent(url, access_token, fileId); 50 | System.out.println(fileInfo.toJSONString()); 51 | } 52 | 53 | private static JSONObject filesUpdatePatchcontent(String url, String access_token, String fileId) throws IOException { 54 | StringBuilder stringBuilder = new StringBuilder(""); 55 | stringBuilder.append("/").append(fileId); 56 | stringBuilder.append("?").append("fields=*"); 57 | stringBuilder.append("&").append("uploadType=content"); 58 | HttpPatch httpPatch = new HttpPatch(url + stringBuilder); 59 | httpPatch.setHeader("Authorization","Bearer " + access_token); 60 | httpPatch.setHeader("Content-Type", "image/jpeg"); 61 | httpPatch.setHeader("Accept", "application/json"); 62 | httpPatch.setHeader("X-Upload-Content-Type", "image/jpeg"); 63 | //httpPut.setHeader("Content-Length", "115085"); 64 | 65 | File file = new File("C:\\Users\\z00502234\\Pictures\\Saved Pictures\\0.jpg");//The path of your local file 66 | if(!file.exists()){ 67 | System.out.print("File not exist"); 68 | return null; 69 | } 70 | FileBody bin = new FileBody(file, ContentType.create("image/jpeg", Consts.UTF_8)); 71 | HttpEntity entity = MultipartEntityBuilder 72 | .create() 73 | .setCharset(Charset.forName("utf-8")) 74 | .addPart("file", bin) 75 | .build(); 76 | httpPatch.setEntity(entity); 77 | RequestConfig requestConfig = RequestConfig.custom() 78 | .setConnectTimeout(50000).setConnectionRequestTimeout(10000) 79 | .setSocketTimeout(50000).build(); 80 | httpPatch.setConfig(requestConfig); 81 | 82 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch); 83 | 84 | try { 85 | HttpEntity responseEntity = response.getEntity(); 86 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 87 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 88 | EntityUtils.consume(responseEntity); 89 | return jsonObject; 90 | }finally { 91 | response.close(); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/utils/HttpClientUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.utils; 18 | 19 | import org.apache.http.client.config.RequestConfig; 20 | import org.apache.http.config.Registry; 21 | import org.apache.http.config.RegistryBuilder; 22 | import org.apache.http.conn.socket.ConnectionSocketFactory; 23 | import org.apache.http.conn.socket.PlainConnectionSocketFactory; 24 | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; 25 | import org.apache.http.impl.client.CloseableHttpClient; 26 | import org.apache.http.impl.client.HttpClients; 27 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; 28 | 29 | import javax.net.ssl.SSLContext; 30 | import javax.net.ssl.TrustManagerFactory; 31 | import java.security.KeyManagementException; 32 | import java.security.KeyStore; 33 | import java.security.KeyStoreException; 34 | import java.security.NoSuchAlgorithmException; 35 | 36 | /** 37 | * 功能描述 38 | * 39 | * @author drive 40 | * @since 2019-12-03 41 | */ 42 | public class HttpClientUtil { 43 | /** 44 | * get httpclient 45 | * @return 46 | */ 47 | public static CloseableHttpClient getClient() { 48 | PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = connectionManager("TLSv1.2", new String[]{"TLSv1.2 TLSv1.1"}, 49 | new String[]{"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 TLS_DHE_RSA_WITH_AES_128_CBC_SHA TLS_DHE_DSS_WITH_AES_128_CBC_SHA"}); 50 | poolingHttpClientConnectionManager.setMaxTotal(400); 51 | poolingHttpClientConnectionManager.setDefaultMaxPerRoute(400); 52 | RequestConfig requestConfig = 53 | RequestConfig.custom().setConnectionRequestTimeout(100).setRedirectsEnabled(false).build(); 54 | 55 | return HttpClients.custom() 56 | .useSystemProperties() 57 | .setConnectionManager(poolingHttpClientConnectionManager) 58 | .setDefaultRequestConfig(requestConfig) 59 | .build(); 60 | } 61 | 62 | /** 63 | * 64 | * @param protocol 65 | * @param supportedProtocols 66 | * @param supportedCipherSuites 67 | * @return 68 | */ 69 | public static PoolingHttpClientConnectionManager connectionManager(String protocol, 70 | String[] supportedProtocols, String[] supportedCipherSuites) { 71 | PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = null; 72 | try { 73 | SSLContext sslContext = SSLContext.getInstance(protocol); 74 | TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 75 | tmf.init((KeyStore) null); 76 | sslContext.init(null, tmf.getTrustManagers(), null); 77 | SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, supportedProtocols, 78 | supportedCipherSuites, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); 79 | 80 | Registry connectionSocketFactory = RegistryBuilder.create() 81 | .register("http", new PlainConnectionSocketFactory()) 82 | .register("https", sslConnectionSocketFactory) 83 | .build(); 84 | poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(connectionSocketFactory); 85 | } catch (KeyStoreException | KeyManagementException | NoSuchAlgorithmException e) { 86 | e.printStackTrace(); 87 | } 88 | return poolingHttpClientConnectionManager; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesCreateMultipart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPost; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | import sun.misc.BASE64Encoder; 28 | 29 | import javax.imageio.ImageIO; 30 | import java.awt.image.BufferedImage; 31 | import java.io.ByteArrayOutputStream; 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.net.MalformedURLException; 35 | /** 36 | * 37 | * 38 | * @author drive 39 | * @since 40 | */ 41 | public class FilesCreateMultipart { 42 | public static void main(String[] args) throws IOException { 43 | 44 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1/files"; 45 | String access_token = "CF3oxnU++pa/3HhS2ZLPQFK8WvK1X5Jo76zCnZEI0ClGl8PkYzum8defyvLHlJfxwGaRiuMPikL7vf6DVlJvwnnzzVmV1mwp4UJuVDg9B/EUsT5VJTO3XQ=="; 46 | 47 | JSONObject fileInfo = filesCreateMultipart(url, access_token); 48 | System.out.println(fileInfo.toJSONString()); 49 | } 50 | 51 | private static JSONObject filesCreateMultipart(String url, String access_token) throws IOException { 52 | StringBuilder stringBuilder = new StringBuilder(""); 53 | stringBuilder.append("?").append("fields=*").append("&").append("uploadType=multipart"); 54 | HttpPost httpPost = new HttpPost(url + stringBuilder); 55 | httpPost.setHeader("Authorization","Bearer " + access_token); 56 | httpPost.setHeader("Content-Type", "multipart/related;boundary=OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO"); 57 | httpPost.setHeader("Accept", "application/json"); 58 | 59 | File file = new File("C:\\Users\\z00502234\\Pictures\\Saved Pictures\\4.jpg");//The path of your local file 60 | if(!file.exists()){ 61 | System.out.print("File not exist"); 62 | return null; 63 | } 64 | String imageBase64 = encodeImgageToBase64(file); 65 | 66 | StringEntity entity = new StringEntity("--OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO\r\nContent-Type: application/json\r\n\r\n{\r\n \"fileName\":\"hwe001\",\r\n \"contentExtras\": {\t\"thumbnail\":{\"content\":\"dGVzdDAwMw==\",\"mimeType\":\"image/png\"}},\r\n \"parents\":[\"applicationData\"]\r\n}\r\n--OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO\r\nContent-Type: application/octet-stream\r\n\r\n" 67 | + imageBase64 68 | + "\r\n--OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO--"); 69 | entity.setContentType("multipart/related;boundary=OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO"); 70 | httpPost.setEntity(entity); 71 | 72 | 73 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost); 74 | 75 | try { 76 | HttpEntity responseEntity = response.getEntity(); 77 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 78 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 79 | EntityUtils.consume(responseEntity); 80 | return jsonObject; 81 | }finally { 82 | response.close(); 83 | } 84 | } 85 | 86 | /* 87 | * 88 | * To encode image for Base64 89 | * */ 90 | public static String encodeImgageToBase64(File imageFile) { 91 | ByteArrayOutputStream outputStream = null; 92 | try { 93 | BufferedImage bufferedImage = ImageIO.read(imageFile); 94 | outputStream = new ByteArrayOutputStream(); 95 | ImageIO.write(bufferedImage, "jpg", outputStream); 96 | } catch (MalformedURLException e1) { 97 | e1.printStackTrace(); 98 | } catch (IOException e) { 99 | e.printStackTrace(); 100 | } 101 | 102 | BASE64Encoder encoder = new BASE64Encoder(); 103 | return encoder.encode(outputStream.toByteArray()); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesUpdatePutmultipart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPut; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.util.EntityUtils; 27 | import sun.misc.BASE64Encoder; 28 | 29 | import javax.imageio.ImageIO; 30 | import java.awt.image.BufferedImage; 31 | import java.io.ByteArrayOutputStream; 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.net.MalformedURLException; 35 | 36 | /** 37 | * 38 | * 39 | * @author drive 40 | * @since 41 | */ 42 | public class FilesUpdatePutmultipart { 43 | public static void main(String[] args) throws IOException { 44 | 45 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1/files"; 46 | String fileId = "AACeEuuAK7wAg6ApbwMVh4QNoCVvDiuwA"; 47 | String access_token = "CF3oxnU++pa/3HhS2ZLPQFK8WvK1X5Jo76zCnZEI0ClGl8PkYzum8defyvLHlJfxwGaRiuMPikL7vf6DVlJvwnnzzVmV1mwp4UJuVDg9B/EUsT5VJTO3XQ=="; 48 | 49 | JSONObject fileInfo = filesUpdatePatchmultipart(url, access_token, fileId); 50 | System.out.println(fileInfo.toJSONString()); 51 | } 52 | 53 | private static JSONObject filesUpdatePatchmultipart(String url, String access_token, String fileId) throws IOException { 54 | StringBuilder stringBuilder = new StringBuilder(""); 55 | stringBuilder.append("/").append(fileId); 56 | stringBuilder.append("?").append("fields=*").append("&").append("uploadType=multipart"); 57 | HttpPut httpPut = new HttpPut(url + stringBuilder); 58 | httpPut.setHeader("Authorization","Bearer " + access_token); 59 | httpPut.setHeader("Content-Type", "multipart/related;boundary=OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO"); 60 | httpPut.setHeader("Accept", "application/json"); 61 | 62 | File file = new File("C:\\Users\\z00502234\\Pictures\\Saved Pictures\\7.jpg");//The path of your local file 63 | if(!file.exists()){ 64 | System.out.print("File not exist"); 65 | return null; 66 | } 67 | String imageBase64 = encodeImgageToBase64(file); 68 | 69 | StringEntity entity = new StringEntity("--OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO\r\nContent-Type: application/json\r\n\r\n{\r\n \"name\":\"hwe001\",\r\n \"contentExtras\": {\t\"thumbnail\":{\"content\":\"dGVzdDAwMw==\",\"mimeType\":\"image/png\"}},\r\n \"parents\":[\"appDataFolder\"]\r\n}\r\n--OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO\r\nContent-Type: application/octet-stream\r\n\r\n" 70 | + imageBase64 71 | + "\r\n--OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO--"); 72 | entity.setContentType("multipart/related;boundary=OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO"); 73 | httpPut.setEntity(entity); 74 | 75 | 76 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPut); 77 | 78 | try { 79 | HttpEntity responseEntity = response.getEntity(); 80 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 81 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 82 | EntityUtils.consume(responseEntity); 83 | return jsonObject; 84 | }finally { 85 | response.close(); 86 | } 87 | } 88 | 89 | public static String encodeImgageToBase64(File imageFile) { 90 | ByteArrayOutputStream outputStream = null; 91 | try { 92 | BufferedImage bufferedImage = ImageIO.read(imageFile); 93 | outputStream = new ByteArrayOutputStream(); 94 | ImageIO.write(bufferedImage, "jpg", outputStream); 95 | } catch (MalformedURLException e1) { 96 | e1.printStackTrace(); 97 | } catch (IOException e) { 98 | e.printStackTrace(); 99 | } 100 | 101 | BASE64Encoder encoder = new BASE64Encoder(); 102 | return encoder.encode(outputStream.toByteArray());// 返回Base64编码过的字节数组字符串 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/com/huawei/drive/demo/files/FilesUpdatePatchmultipart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package com.huawei.drive.demo.files; 18 | 19 | import com.alibaba.fastjson.JSON; 20 | import com.alibaba.fastjson.JSONObject; 21 | import com.huawei.drive.demo.utils.HttpClientUtil; 22 | import org.apache.http.HttpEntity; 23 | import org.apache.http.client.methods.CloseableHttpResponse; 24 | import org.apache.http.client.methods.HttpPatch; 25 | import org.apache.http.client.methods.HttpPost; 26 | import org.apache.http.entity.StringEntity; 27 | import org.apache.http.util.EntityUtils; 28 | import sun.misc.BASE64Encoder; 29 | 30 | import javax.imageio.ImageIO; 31 | import java.awt.image.BufferedImage; 32 | import java.io.ByteArrayOutputStream; 33 | import java.io.File; 34 | import java.io.IOException; 35 | import java.net.MalformedURLException; 36 | 37 | /** 38 | * 39 | * 40 | * @author drive 41 | * @since 42 | */ 43 | public class FilesUpdatePatchmultipart { 44 | public static void main(String[] args) throws IOException { 45 | 46 | String url = "https://drive.cloud.hicloud.com/upload/drive/v1/files"; 47 | String fileId = "AACeEuuAK7wAg6ApbwMVh4QNoCVvDiuwA"; 48 | String access_token = "CF3oxnU++pa/3HhS2ZLPQFK8WvK1X5Jo76zCnZEI0ClGl8PkYzum8defyvLHlJfxwGaRiuMPikL7vf6DVlJvwnnzzVmV1mwp4UJuVDg9B/EUsT5VJTO3XQ=="; 49 | 50 | JSONObject fileInfo = filesUpdatePatchmultipart(url, access_token, fileId); 51 | System.out.println(fileInfo.toJSONString()); 52 | } 53 | 54 | private static JSONObject filesUpdatePatchmultipart(String url, String access_token, String fileId) throws IOException { 55 | StringBuilder stringBuilder = new StringBuilder(""); 56 | stringBuilder.append("/").append(fileId); 57 | stringBuilder.append("?").append("fields=*").append("&").append("uploadType=multipart"); 58 | HttpPatch httpPatch = new HttpPatch(url + stringBuilder); 59 | httpPatch.setHeader("Authorization","Bearer " + access_token); 60 | httpPatch.setHeader("Content-Type", "multipart/related;boundary=OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO"); 61 | httpPatch.setHeader("Accept", "application/json"); 62 | 63 | File file = new File("C:\\Users\\z00502234\\Pictures\\Saved Pictures\\6.jpg");//The path of your local file 64 | if(!file.exists()){ 65 | System.out.print("File not exist"); 66 | return null; 67 | } 68 | String imageBase64 = encodeImgageToBase64(file); 69 | 70 | StringEntity entity = new StringEntity("--OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO\r\nContent-Type: application/json\r\n\r\n{\r\n \"name\":\"hwe001\",\r\n \"contentExtras\": {\t\"thumbnail\":{\"content\":\"dGVzdDAwMw==\",\"mimeType\":\"image/png\"}},\r\n \"parents\":[\"appDataFolder\"]\r\n}\r\n--OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO\r\nContent-Type: application/octet-stream\r\n\r\n" 71 | + imageBase64 72 | + "\r\n--OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO--"); 73 | entity.setContentType("multipart/related;boundary=OP8XTaXZ0UZs-Sjlefcj2OWskqXWwVQO"); 74 | httpPatch.setEntity(entity); 75 | 76 | 77 | CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPatch); 78 | 79 | try { 80 | HttpEntity responseEntity = response.getEntity(); 81 | String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null; 82 | JSONObject jsonObject = (JSONObject) JSON.parse(ret); 83 | EntityUtils.consume(responseEntity); 84 | return jsonObject; 85 | }finally { 86 | response.close(); 87 | } 88 | } 89 | 90 | public static String encodeImgageToBase64(File imageFile) { 91 | ByteArrayOutputStream outputStream = null; 92 | try { 93 | BufferedImage bufferedImage = ImageIO.read(imageFile); 94 | outputStream = new ByteArrayOutputStream(); 95 | ImageIO.write(bufferedImage, "jpg", outputStream); 96 | } catch (MalformedURLException e1) { 97 | e1.printStackTrace(); 98 | } catch (IOException e) { 99 | e.printStackTrace(); 100 | } 101 | 102 | BASE64Encoder encoder = new BASE64Encoder(); 103 | return encoder.encode(outputStream.toByteArray());// 返回Base64编码过的字节数组字符串 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | 3 | Version 2.0, January 2004 4 | 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 16 | 17 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 18 | 19 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 20 | 21 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 22 | 23 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 24 | 25 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 26 | 27 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 28 | 29 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 30 | 31 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 32 | 33 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 34 | 35 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 36 | 37 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 38 | You must cause any modified files to carry prominent notices stating that You changed the files; and 39 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 40 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 41 | 42 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 43 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 44 | 45 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 46 | 47 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 48 | 49 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 50 | 51 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 52 | 53 | END OF TERMS AND CONDITIONS --------------------------------------------------------------------------------