全部产品

Java SDK 简介

更新时间:2020-03-31 21:59:36

下载地址

https://github.com/aliyun/aliyun-ccp

安装步骤

安装 Java 开发环境

目前,CCPJava SDK 支持 J2SE 6.0 及以上的 Java 运行环境,您可以从 Java 官方网站 下载并按说明安装 Java 开发环境。

安装 CCP Java SDK

安装完 Java 开发环境后,您需要安装CCP SDK,将下面的依赖加入 pom.xml 。

CCPPath

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>ccp-client</artifactId>
  4. <version>RELEASE</version>
  5. </dependency>

OSSPath

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>ccp-oss-client</artifactId>
  4. <version>RELEASE</version>
  5. </dependency>

注意:请关注 Git Hub提供的最新版本,查看相关功能并选择使用。

初始化Client

使用前提是您已经开通CCP服务, 并且在控制台创建了域实例。参见快速搭建云盘服务。之后您可以按需初始化CCPClient 或者 OSSClient。

AK & SK 初始化客户端

AK, SK 的获取详见 密钥管理页面。选择一对用于 SDK 的访问密钥对。如果没有,请创建一对新访问密钥,且保证它处于启用状态。有关如何创建访问密钥,参见 创建访问密钥

  1. import com.aliyun.ccp.ccpclient.Client;
  2. import com.aliyun.ccp.ccpclient.models.*;
  3. public class Demo {
  4. private static Client client;
  5. private static RuntimeOptions runtime;
  6. public static void createClient() throws IllegalAccessException {
  7. Config config = new Config();
  8. config.domainId = "your domainId";
  9. config.protocol = "https";
  10. config.accessKeyId = System.getenv("accessKeyId");
  11. config.accessKeySecret = System.getenv("accessKeySecret");
  12. client = new Client(config);
  13. runtime = new RuntimeOptions();
  14. }
  15. }

AccessToken & RefreshToken 初始化客户端

clientId, clientSecret 的获取详见应用接入指南

  1. import com.aliyun.ccp.ccpclient.Client;
  2. import com.aliyun.ccp.ccpclient.models.*;
  3. public class Demo {
  4. private static Client client;
  5. private static RuntimeOptions runtime;
  6. public static void createClient() throws IllegalAccessException {
  7. Config config = new Config();
  8. config.domainId = "your domainId";
  9. config.protocol = "https";
  10. config.clientId = System.getenv("clientId");
  11. config.clientSecret = System.getenv("clientSecret");
  12. config.accessToken = System.getenv("accessToken");
  13. config.refreshToken = System.getenv("refreshToken");
  14. config.expireTime = System.getenv("expireTime");
  15. client = new Client(config);
  16. runtime = new RuntimeOptions();
  17. }
  18. }

注意:AK & SK 模式 和 Access Token & Refresh Token 模式 同时只能存在一种

构造请求

Account 相关 API

获取图片验证码

  • 以下代码用于获取图片验证码,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 获取图片验证码
  2. public static void getCaptcha() throws Exception {
  3. try {
  4. GetCaptchaRequestModel requestModel = new GetCaptchaRequestModel();
  5. GetCaptchaRequest getCaptchaRequest = new GetCaptchaRequest();
  6. getCaptchaRequest.appId = "***********";
  7. requestModel.body = getCaptchaRequest;
  8. GetCaptchaModel captcha = client.getCaptcha(requestModel, runtime);
  9. // 打印结果
  10. System.out.println(new Gson().toJson(captcha.body.captcha));
  11. } catch (TeaException e) {
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getCode());
  14. System.out.println(e.getData());
  15. }
  16. }
  • 返回结果
  1. {
  2. "captcha":"iVBORw0KGgoAAAANSUhEUgAAAFAAAAAaCAIAAACvsEzwAAABFUlEQVR42u3YwQ7CIAwGYOKDaLya7OBL+BDePRoT4/vPJSSEjFJ+2oEIW3oy0PHRDnVmHuwyO3gH93J9Xm85+PA4+REOmKYLGbGE5/vVBn/f2/O4hMZs9FrSjIMdtVEwKSSLTG7Bb8HZLc30MALmB7QLlmkHAiPa3sDIsE7AYHkbAtvvaw0YHNlQhRezZeee0nh5BWC/EkVamjHHtqAoWGbOe4ZtqZFfWrmHcxhIhYuD3Z2S2gpgmVn450G2u8i5mOzn1aFlV7LKwCQ0FRaqTOWcsSPazvUzZIPJbStaahCMT48lNIjHD0GpkQzKftkMzK9e8/yHecLPwZ0ihZuBK7yFKTq9uXdamp7/M7Df22JPcsxw4C/GgzEzOWpc1QAAAABJRU5ErkJggg==",
  3. "captchaFormat":"png",
  4. "captchaId":"f644d0b2a7d21a3caddb17377c90c28e8DPXYUIfvs3"
  5. }

获取短信验证码

  • 以下代码用于获取短信验证码,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void getMNSCode() throws Exception {
  2. try {
  3. MobileSendSmsCodeRequestModel requestModel = new MobileSendSmsCodeRequestModel();
  4. MobileSendSmsCodeRequest sendSmsCodeRequest = new MobileSendSmsCodeRequest();
  5. sendSmsCodeRequest.appId = appId;
  6. sendSmsCodeRequest.phoneNumber = "13**********5";
  7. sendSmsCodeRequest.type = "change_password";
  8. requestModel.body = sendSmsCodeRequest;
  9. MobileSendSmsCodeModel response = client.mobileSendSmsCode(requestModel, runtime);
  10. System.out.println(new Gson().toJson(response.body));
  11. } catch (TeaException e) {
  12. System.out.println(e.getCode());
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getData());
  15. }
  16. }
  • 返回结果
  1. {
  2. "smsCodeId":"b40bba70b37d74**********************6j3IW7HP"
  3. }

验证手机号是否注册

  • 以下代码用于验证手机号是否存在,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void checkMobileIsExist() throws Exception {
  2. try {
  3. MobileCheckExistRequestModel requestModel = new MobileCheckExistRequestModel();
  4. MobileCheckExistRequest checkExistRequest = new MobileCheckExistRequest();
  5. checkExistRequest.appId = appId;
  6. checkExistRequest.phoneNumber = "13*****25";
  7. requestModel.body = checkExistRequest;
  8. CheckExistModel checkExistResponse = client.checkExist(requestModel, runtime);
  9. System.out.println(new Gson().toJson(checkExistResponse.body));
  10. } catch (TeaException e) {
  11. System.out.println(e.getCode());
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getData());
  14. }
  15. }
  • 返回结果
  1. {
  2. "isExist":true,
  3. "phoneNumber":"13****25"
  4. }

手机号注册

  • 以下代码用于手机号注册,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void register() throws Exception {
  2. try {
  3. MobileRegisterRequestModel requestModel = new MobileRegisterRequestModel();
  4. MobileRegisterRequest registerRequest = new MobileRegisterRequest();
  5. registerRequest.appId = appId;
  6. registerRequest.phoneNumber = "132****225";
  7. registerRequest.smsCode = "0****0";
  8. registerRequest.smsCodeId = "674e************JRuoQgRu0R";
  9. requestModel.body = registerRequest;
  10. RegisterModel tokenResponse = client.register(requestModel, runtime);
  11. System.out.println(new Gson().toJson(tokenResponse.body));
  12. } catch (TeaException e) {
  13. System.out.println(e.getCode());
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getData());
  16. }
  17. }
  • 返回结果
  1. {
  2. "access_token": "eyJhbGc***************iOiJSUzI1NiI",
  3. "refresh_token": "fvw1FLZ************tGjXxJl",
  4. "expires_in": 7200,
  5. "token_type": "Bearer",
  6. "user_id": "6c23c98d3***************3f9f5211",
  7. "user_name": "132******225",
  8. "avatar": "",
  9. "nick_name": "1329*****225",
  10. "default_drive_id": "",
  11. "role": "admin",
  12. "expire_time": "2019-10-30T11:44:24Z",
  13. "state": "",
  14. "exist_link": [],
  15. "need_link": false,
  16. "user_data": {}
  17. }

手机号短信登录

  • 以下代码用于短信登录,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void mnsLogin() throws Exception {
  2. try {
  3. // mns login
  4. MobileLoginRequestModel requestModel = new MobileLoginRequestModel();
  5. MobileLoginRequest mobileLoginRequest = new MobileLoginRequest();
  6. mobileLoginRequest.appId = appId;
  7. mobileLoginRequest.phoneNumber = "132**********#=&";
  8. mobileLoginRequest.smsCode = "123456";
  9. mobileLoginRequest.smsCodeId = changePasswordCode;
  10. requestModel.body = mobileLoginRequest;
  11. LoginModel tokenResponse = client.login(requestModel, runtime);
  12. System.out.println(new Gson().toJson(tokenResponse));
  13. } catch (TeaException e) {
  14. System.out.println(e.getCode());
  15. System.out.println(e.getMessage());
  16. System.out.println(e.getData());
  17. }
  18. }

设置登录密码

  • 以下代码用于设置登录密码,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void setPassWord() throws Exception {
  2. try {
  3. DefaultSetPasswordRequestModel requestModel = new DefaultSetPasswordRequestModel();
  4. DefaultSetPasswordRequest setPasswordRequest = new DefaultSetPasswordRequest();
  5. setPasswordRequest.appId = appId;
  6. setPasswordRequest.newPassword = "1234567";
  7. setPasswordRequest.state = "";
  8. requestModel.body =setPasswordRequest;
  9. client.setPassword(requestModel, runtime);
  10. } catch (TeaException e) {
  11. System.out.println(e.getCode());
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getData());
  14. }
  15. }

密码登录

  • 以下代码用于密码登录,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 密码登录
  2. public static void passwordLogin() throws Exception {
  3. try {
  4. MobileLoginRequestModel requestModel = new MobileLoginRequestModel();
  5. MobileLoginRequest mobileLoginRequest = new MobileLoginRequest();
  6. mobileLoginRequest.appId = appId;
  7. mobileLoginRequest.phoneNumber = "132******25";
  8. mobileLoginRequest.password = "123********456";
  9. requestModel.body = mobileLoginRequest;
  10. LoginModel tokenResponse = client.login(requestModel, runtime);
  11. System.out.println(new Gson().toJson(tokenResponse.body));
  12. assertNotNull(tokenResponse.body.accessToken);
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(e.getData());
  17. }
  18. }

修改登录密码

  • 以下代码用于修改登录密码,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void changePassWord() throws Exception {
  2. try {
  3. DefaultChangePasswordRequestModel requestModel = new DefaultChangePasswordRequestModel();
  4. DefaultChangePasswordRequest changePasswordRequest = new DefaultChangePasswordRequest();
  5. changePasswordRequest.appId = appId;
  6. changePasswordRequest.phoneNumber = "13*****25";
  7. changePasswordRequest.newPassword = "12*****9";
  8. changePasswordRequest.smsCode = "6*****73";
  9. changePasswordRequest.smsCodeId = "9751***********wru";
  10. requestModel.body = changePasswordRequest;
  11. client.changePassword(requestModel, runtime);
  12. } catch (TeaException e) {
  13. System.out.println(e.getCode());
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getData());
  16. }
  17. }

通过刷新令牌获取访问令牌

  • 以下代码用于刷新token,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void getTokenByRefreshToken() throws Exception {
  2. try {
  3. TokenRequestModel requestModel = new TokenRequestModel();
  4. TokenRequest tokenRequest = new TokenRequest();
  5. tokenRequest.appId = appId;
  6. tokenRequest.grantType = "refresh_token";
  7. tokenRequest.refreshToken = "CzuJktQK*********TAVTJorJa";
  8. requestModel.body = new TokenRequest();
  9. TokenModel tokenResponse = client.token(requestModel, runtime);
  10. System.out.println(new Gson().toJson(tokenResponse));
  11. } catch (TeaException e) {
  12. System.out.println(e.getCode());
  13. System.out.println(e.getMessage());
  14. }
  15. }

通过账号获取访问令牌

  • 以下代码用于获取用户认证方式,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void getAccessTokenByLinkInfo() throws Exception {
  2. try {
  3. // 此接口需要ak,sk调用, 请使用ak, sk初始化客户端
  4. GetAccessTokenByLinkInfoRequestModel requestModel = new GetAccessTokenByLinkInfoRequestModel();
  5. GetAccessTokenByLinkInfoRequest getAccessTokenByLinkInfoRequest = new GetAccessTokenByLinkInfoRequest();
  6. getAccessTokenByLinkInfoRequest.identity = "132********25";
  7. getAccessTokenByLinkInfoRequest.type = "mobile";
  8. requestModel.body = getAccessTokenByLinkInfoRequest;
  9. GetAccessTokenByLinkInfoModel tokenResponse = client.getAccessTokenByLinkInfo(requestModel, runtime);
  10. System.out.println(new Gson().toJson(tokenResponse.body));
  11. } catch (TeaException e) {
  12. System.out.println(e.getCode());
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getData());
  15. }
  16. }

获取用户绑定信息

  • 以下代码用于获取用户认证方式,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void getLinkInfoByUserId() throws Exception {
  2. try {
  3. // 此接口需要ak,sk调用, 请使用ak, sk初始化客户端
  4. GetLinkInfoByUserIDRequestModel requestModel = new GetLinkInfoByUserIDRequestModel();
  5. GetLinkInfoByUserIDRequest linkInfoByUserIDRequest = new GetLinkInfoByUserIDRequest();
  6. linkInfoByUserIDRequest.userId = "6c23*********5211";
  7. requestModel.body = linkInfoByUserIDRequest;
  8. GetLinkInfoByUserIdModel listResponse = client.getLinkInfoByUserId(requestModel, runtime);
  9. System.out.println(new Gson().toJson(listResponse.body));
  10. } catch (TeaException e) {
  11. System.out.println(e.getCode());
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getData());
  14. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "authenticationType":"mobile",
  5. "createdAt":1571905906341,
  6. "domainId":"daily1405",
  7. "identity":"13******225",
  8. "lastLoginTime":1571905906341,
  9. "status":"normal",
  10. "userId":"6c23c9******3f9f5211"
  11. }
  12. ]
  13. }

获取用户认证方式

  • 以下代码用于获取用户认证方式,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void getLinkInfo() throws Exception {
  2. try {
  3. // 此接口需要ak,sk调用, 请使用ak, sk初始化客户端
  4. GetByLinkInfoRequestModel requestModel = new GetByLinkInfoRequestModel();
  5. GetByLinkInfoRequest getByLinkInfoRequest = new GetByLinkInfoRequest();
  6. getByLinkInfoRequest.identity = "adsfqwrsfad";
  7. getByLinkInfoRequest.type = "ding";
  8. requestModel.body = getByLinkInfoRequest;
  9. GetLinkInfoModel linkInfoResponse = client.getLinkInfo(requestModel, runtime);
  10. System.out.println(new Gson().toJson(linkInfoResponse.body));
  11. } catch (TeaException e) {
  12. System.out.println(e.getCode());
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getData());
  15. }
  16. }
  • 返回结果
  1. {
  2. "authenticationType":"ding",
  3. "createdAt":1572427460313,
  4. "domainId":"daily1405",
  5. "identity":"adsfqwrsfad",
  6. "lastLoginTime":1572427460313,
  7. "status":"wait_link",
  8. "userId":"6c23c98*****7d8b3f9f5211"
  9. }

绑定用户认证方式

  • 以下代码用于绑定用户认证方式,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void userLinkInfo() throws Exception {
  2. try {
  3. // 此接口需要ak,sk调用, 请使用ak, sk初始化客户端
  4. AccountLinkRequestModel requestModel = new AccountLinkRequestModel();
  5. AccountLinkRequest linkInfo = new AccountLinkRequest();
  6. linkInfo.type = "taobao";
  7. linkInfo.identity = "1234";
  8. linkInfo.userId = "1eb15*************eff97708cb";
  9. linkInfo.status ="wait_link";
  10. requestModel.body = linkInfo;
  11. LinkModel tokenResponse = new_client.link(requestModel, runtime);
  12. System.out.println(new Gson().toJson(tokenResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getCode());
  15. System.out.println(e.getMessage());
  16. System.out.println(e.getData());
  17. }
  18. }
  • 返回结果
  1. {
  2. "avatar":"",
  3. "defaultDriveId":"",
  4. "existLink":[
  5. {
  6. "identity":"13*****225",
  7. "type":"mobile"
  8. }
  9. ],
  10. "expireTime":"",
  11. "expiresIn":300,
  12. "needLink":true,
  13. "nickName":"",
  14. "refreshToken":"",
  15. "role":"",
  16. "state":"",
  17. "tokenType":"Bearer",
  18. "userId":"",
  19. "userName":""
  20. }

取消绑定关系

  • 以下代码用于取消绑定关系,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void cancelLink() throws Exception {
  2. try {
  3. CancelLinkRequestModel requestModel = new CancelLinkRequestModel();
  4. CancelLinkRequest cancelLinkRequest = new CancelLinkRequest();
  5. cancelLinkRequest.temporaryToken = "eyJhbGciOiJSUzI1N*****pwc";
  6. requestModel.body = cancelLinkRequest;
  7. CancelLinkModel tokenResponse = client.cancelLink(requestModel, runtime);
  8. System.out.println(new Gson().toJson(tokenResponse.body));;
  9. } catch (TeaException e) {
  10. System.out.println(e.getCode());
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getData());
  13. }
  14. }

确定绑定关系

  • 以下代码用于确定绑定关系,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  • 此接口只支持Access Token,不要使用AK,SK初始化客户端。
  1. public void confirmLink() throws Exception {
  2. try {
  3. ConfirmLinkRequestModel requestModel = new ConfirmLinkRequestModel();
  4. ConfirmLinkRequest confirmLinkRequest = new ConfirmLinkRequest();
  5. confirmLinkRequest.temporaryToken = "eyJhbGciOiJSUzI1NiIsI(***qE";
  6. requestModel.body = confirmLinkRequest;
  7. ConfirmLinkModel tokenResponse = client.confirmLink(requestModel, runtime);
  8. System.out.println(new Gson().toJson(tokenResponse));
  9. } catch (TeaException e) {
  10. System.out.println(e.getCode());
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getData());
  13. }
  14. }

User 相关 API

创建User

  • 以下代码用于创建User,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 创建User
  2. public static void createUser() throws Exception {
  3. try {
  4. CreateUserRequestModel requestModel = new CreateUserRequestModel();
  5. CreateUserRequest createUserRequest = new CreateUserRequest();
  6. createUserRequest.userId = "***";
  7. createUserRequest.role = "***";;
  8. createUserRequest.userName = "***";;
  9. requestModel.body = createUserRequest;
  10. CreateUserModel createUserResponse = client.createUser(requestModel, runtimeOptions);
  11. System.out.println(new Gson().toJson(createUserResponse.body));
  12. } catch (TeaException e) {
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getCode());
  15. System.out.println(new Gson().toJson(e.getData()));
  16. }
  17. }
  • 返回结果
  1. {
  2. "avatar":"",
  3. "createdAt":1572225460185,
  4. "defaultDriveId":"",
  5. "description":"",
  6. "domainId":"daily1405",
  7. "email":"",
  8. "nickName":"",
  9. "phone":"",
  10. "role":"user",
  11. "status":"enabled",
  12. "updatedAt":0,
  13. "userId":"test_user",
  14. "userName":"test_user"
  15. }

获取User

  • 以下代码用于获取User,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. //获取User
  2. public static void getUser() throws Exception {
  3. try {
  4. GetUserRequestModel requestModel = new GetUserRequestModel();
  5. GetUserRequest getUserRequest = new GetUserRequest();
  6. getUserRequest.userId = "****";
  7. requestModel.body = getUserRequest;
  8. GetUserModel getUserResponse = client.getUser(requestModel, runtimeOptions);
  9. System.out.println(new Gson().toJson(getUserResponse.body));
  10. } catch (TeaException e) {
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getCode());
  13. System.out.println(new Gson().toJson(e.getData()));
  14. }
  15. }
  • 返回结果
  1. {
  2. "avatar":"",
  3. "createdAt":1572226149810,
  4. "defaultDriveId":"",
  5. "description":"",
  6. "domainId":"daily1405",
  7. "email":"",
  8. "nickName":"",
  9. "phone":"",user
  10. "role":"user",
  11. "status":"enabled",
  12. "updatedAt":0,
  13. "userId":"test_user",
  14. "userName":"test_user"
  15. }

列举User

  • 以下代码用于列举User,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. //列举User
  2. public static void listUser() throws Exception {
  3. try {
  4. ListUserRequestModel requestModel = new ListUserRequestModel();
  5. ListUserRequest listUserRequest = new ListUserRequest();
  6. listUserRequest.limit = 10;
  7. requestModel.body = listUserRequest;
  8. ListUsersModel listUserResponse = client.listUsers(requestModel, runtimeOptions);
  9. System.out.println(new Gson().toJson(listUserResponse.body));
  10. } catch (TeaException e) {
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getCode());
  13. System.out.println(new Gson().toJson(e.getData()));
  14. }
  15. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "avatar":"",
  5. "createdAt":1571903980532,
  6. "defaultDriveId":"",
  7. "description":"",
  8. "domainId":"daily1405",
  9. "email":"",
  10. "nickName":"xxxxxx",
  11. "phone":"",
  12. "role":"user",
  13. "status":"enabled",
  14. "updatedAt":1571903980532,
  15. "userId":"1eb15a*****************8cb",
  16. "userName":"xxxxxx"
  17. },
  18. {
  19. "avatar":"",
  20. "createdAt":1571915575499,
  21. "defaultDriveId":"",
  22. "description":"",
  23. "domainId":"daily1405",
  24. "email":"",
  25. "nickName":"xxxxxx",
  26. "phone":"",
  27. "role":"user",
  28. "status":"enabled",
  29. "updatedAt":1571915575499,
  30. "userId":"51901a4************dbf5",
  31. "userName":"xxxxxx"
  32. },
  33. {
  34. "avatar":"",
  35. "createdAt":1571903776751,
  36. "defaultDriveId":"",
  37. "description":"",
  38. "domainId":"daily1405",
  39. "email":"",
  40. "nickName":"xxxxxx",
  41. "phone":"",
  42. "role":"user",
  43. "status":"enabled",
  44. "updatedAt":1571903776751,
  45. "userId":"621a3c***************8ecd",
  46. "userName":"xxxxxx"
  47. },
  48. {
  49. "avatar":"",
  50. "createdAt":1571905906346,
  51. "defaultDriveId":"",
  52. "description":"",
  53. "domainId":"daily1405",
  54. "email":"",
  55. "nickName":"1329***25",
  56. "phone":"132****25",
  57. "role":"admin",
  58. "status":"enabled",
  59. "updatedAt":1571907859554,
  60. "userId":"6c23c98****************f5211",
  61. "userName":"132**********5"
  62. },
  63. {
  64. "avatar":"",
  65. "createdAt":1572226835585,
  66. "defaultDriveId":"",
  67. "description":"",
  68. "domainId":"daily1405",
  69. "email":"",
  70. "nickName":"",
  71. "phone":"",
  72. "role":"admin",
  73. "status":"enabled",
  74. "updatedAt":0,
  75. "userId":"xxxxxx",
  76. "userName":"xxxxxx"
  77. },
  78. {
  79. "avatar":"",
  80. "createdAt":1571887988846,
  81. "defaultDriveId":"",
  82. "description":"",
  83. "domainId":"daily1405",
  84. "email":"",
  85. "nickName":"superadmin",
  86. "phone":"",
  87. "role":"superadmin",
  88. "status":"enabled",
  89. "updatedAt":0,
  90. "userId":"superadmin",
  91. "userName":"superadmin"
  92. }
  93. ],
  94. "nextMarker":""
  95. }

更新User

  • 以下代码用于更新User,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. //更新User
  2. public static void updateUser() throws Exception {
  3. try {
  4. UpdateUserRequestModel requestModel = new UpdateUserRequestModel();
  5. UpdateUserRequest updateUserRequest = new UpdateUserRequest();
  6. updateUserRequest.description = "test_user";
  7. updateUserRequest.userId = "***";
  8. requestModel.body = updateUserRequest;
  9. UpdateUserModel updateUserResponse = client.updateUser(requestModel, runtimeOptions);
  10. System.out.println(new Gson().toJson(updateUserResponse.body));
  11. } catch (TeaException e) {
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getCode());
  14. System.out.println(new Gson().toJson(e.getData()));
  15. }
  16. }
  • 返回结果
  1. {
  2. "avatar":"",
  3. "createdAt":1572226835585,
  4. "defaultDriveId":"",
  5. "description":"test_user",
  6. "domainId":"daily1405",
  7. "email":"",
  8. "nickName":"",
  9. "phone":"",
  10. "role":"user",
  11. "status":"enabled",
  12. "updatedAt":1572226880276,
  13. "userId":"test_user",
  14. "userName":"test_user"
  15. }

搜索User

  • 以下代码用于搜索User,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // search user
  2. public static void searchUser() throws Exception {
  3. try {
  4. SearchUserRequestModel requestModel = new SearchUserRequestModel();
  5. SearchUserRequest searchUserRequest = new SearchUserRequest();
  6. searchUserRequest.userName = "***";
  7. requestModel.body = searchUserRequest;
  8. SearchUserModel listUserResponse1 = client.searchUser(requestModel, runtimeOptions);
  9. System.out.println(new Gson().toJson(listUserResponse1.body));
  10. } catch (TeaException e) {
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getCode());
  13. System.out.println(new Gson().toJson(e.getData()));
  14. }
  15. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "avatar":"",
  5. "createdAt":1571915575499,
  6. "defaultDriveId":"",
  7. "description":"",
  8. "domainId":"daily1405",
  9. "email":"",
  10. "nickName":"刘***",
  11. "phone":"",
  12. "role":"user",
  13. "status":"enabled",
  14. "updatedAt":1571915575499,
  15. "userId":"5190******************2edbf5",
  16. "userName":"刘***"
  17. }
  18. ],
  19. "nextMarker":""
  20. }

删除User

  • 以下代码用于删除User,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 删除User
  2. public static void deleteUser() throws Exception {
  3. try {
  4. DeleteUserRequestModel requestModel = new DeleteUserRequestModel();
  5. DeleteUserRequest deleteUserRequest = new DeleteUserRequest();
  6. deleteUserRequest.userId = "***";
  7. requestModel.body = deleteUserRequest;
  8. DeleteUserModel deleteUserResponse = client.deleteUser(requestModel, runtimeOptions);
  9. //此接口没有返回body
  10. } catch (TeaException e) {
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getCode());
  13. System.out.println(new Gson().toJson(e.getData()));
  14. }
  15. }

OSSPath Drive 相关API

说明

  • OSSPath 创建drive 需要先拿到store_id,需要先调用/v2/domain/list_stores的接口。

创建drive

  • 以下代码用于创建Drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public static void createDrive() throws Exception {
  2. try {
  3. // 获取store_id
  4. AdminListStoresRequestModel requestModel = new AdminListStoresRequestModel();
  5. AdminListStoresRequest listStoresRequest = new AdminListStoresRequest();
  6. requestModel.body = listStoresRequest;
  7. AdminListStoresModel listStoresResponse = client.adminListStores(requestModel, runtime);
  8. //打印结果
  9. System.out.println(new Gson().toJson(listStoresResponse.body));
  10. // 根据自己的需求从返回的结果中选择store_id
  11. String storeId = listStoresResponse.body.items.get(0).storeId;
  12. //创建drive
  13. reateDriveRequestModel requestModel1 = new CreateDriveRequestModel();
  14. CreateDriveRequest createDriveRequest = new CreateDriveRequest();
  15. createDriveRequest.totalSize = 1000000L;
  16. createDriveRequest.driveName = "java-sdk-test_drive";
  17. createDriveRequest.description = "java-sdk-test_drive";
  18. createDriveRequest.driveType = "normal";
  19. createDriveRequest.relativePath = "/test_drive/";
  20. createDriveRequest.storeId = storeId;
  21. createDriveRequest.owner = userId;
  22. requestModel1.body = createDriveRequest;
  23. CreateDriveModel createDriveResponse = client.createDrive(requestModel1, runtime);
  24. // 打印结果
  25. System.out.println(new Gson().toJson(createDriveResponse.body));
  26. } catch (TeaException e) {
  27. System.out.println(e.getMessage());
  28. System.out.println(e.getCode());
  29. System.out.println(new Gson().toJson(e.getData()));
  30. }
  31. }
  • 返回结果
  1. // list_stores response
  2. {
  3. "items":[
  4. {
  5. "accelerateEndpoint":"",
  6. "basePath":"",
  7. "bucket":"ccp-daily-test",
  8. "customizedEndpoint":"",
  9. "endpoint":"https://oss-cn-hangzhou.aliyuncs.com",
  10. "internalEndpoint":"",
  11. "ownership":"custom",
  12. "policy":"",
  13. "roleArn":"",
  14. "storeId":"90fba27e9c40452d91d83b204aee1d9b",
  15. "type":"oss"
  16. }
  17. ]
  18. }
  19. // create drive response
  20. {
  21. "requestId":"E72DDD97-E99F-437D-B0B8-7C752C4E9548",
  22. "domainId":"daily1405",
  23. "driveId":"1902"
  24. }

列举drive

  • 以下代码用于列举Drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 列举 Drive
  2. public static void listDrive() throws Exception {
  3. try {
  4. ListDriveRequestModel requestModel = new ListDriveRequestModel();
  5. ListDriveRequest listDriveRequest = new ListDriveRequest();
  6. listDriveRequest.limit = 1;
  7. listDriveRequest.owner = userId;
  8. requestModel.body = listDriveRequest;
  9. ListDrivesModel listDriveResponse = client.listDrives(requestModel3, runtime);
  10. // 打印结果
  11. System.out.println(new Gson().toJson(listDriveResponse.body));
  12. } catch (TeaException e) {
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getCode());
  15. System.out.println(new Gson().toJson(e.getData()));
  16. }
  17. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "creator":"6c23c*************211",
  5. "description":"drive",
  6. "domainId":"daily1405",
  7. "driveId":"1902",
  8. "driveName":"test_drive",
  9. "driveType":"normal",
  10. "owner":"6c23c*************211",
  11. "relativePath":"/test_drive/",
  12. "status":"enabled",
  13. "storeId":"90fba27e9c40452d91d83b204aee1d9b",
  14. "totalSize":1000000,
  15. "usedSize":0
  16. }
  17. ],
  18. "nextMarker":""
  19. }

查询drive

  • 以下代码用于查询Drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 查询 Drive
  2. public static void getDrive() throws Exception {
  3. try {
  4. GetDriveRequestModel requestModel = new GetDriveRequestModel();
  5. GetDriveRequest getDriveRequest = new GetDriveRequest();
  6. getDriveRequest.driveId = "2801";
  7. requestModel.body = getDriveRequest;
  8. GetDriveModel getDriveResponse = client.getDrive(requestModel, runtime);
  9. System.out.println(new Gson().toJson(getDriveResponse.body));
  10. } catch (TeaException e) {
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getCode());
  13. System.out.println(new Gson().toJson(e.getData()));
  14. }
  15. }
  • 返回结果
  1. {
  2. "creator":"6c23c9*************f5211",
  3. "description":"test_drive",
  4. "domainId":"daily1405",
  5. "driveId":"1902",
  6. "driveName":"test_drive",
  7. "driveType":"normal",
  8. "owner":"6c23c9***************f5211",
  9. "relativePath":"/test_drive/",
  10. "status":"enabled",
  11. "storeId":"90fba27e9c40452d91d83b204aee1d9b",
  12. "totalSize":1000000,
  13. "usedSize":0
  14. }

列举drive

  • 以下代码用于更新Drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 列举 Drive
  2. public static void listDrive() throws Exception {
  3. try {
  4. ListDriveRequestModel requestModel = new ListDriveRequestModel();
  5. ListDriveRequest listDriveRequest = new ListDriveRequest();
  6. listDriveRequest.limit = 1;
  7. listDriveRequest.owner = userId;
  8. requestModel.body = listDriveRequest;
  9. ListDrivesModel listDriveResponse = client.listDrives(requestModel, runtime);
  10. // 打印结果
  11. System.out.println(new Gson().toJson(listDriveResponse.body));
  12. } catch (TeaException e) {
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getCode());
  15. System.out.println(new Gson().toJson(e.getData()));
  16. }
  17. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "creator":"",
  5. "description":"",
  6. "domainId":"daily1405",
  7. "driveId":"603",
  8. "driveName":"test_drive",
  9. "driveType":"normal",
  10. "owner":"****",
  11. "relativePath":"/test_drive/",
  12. "status":"enabled",
  13. "storeId":"55ff********904",
  14. "totalSize":100000,
  15. "usedSize":0
  16. }
  17. ],
  18. "nextMarker":""
  19. }

更新drive

  • 以下代码用于更新Drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 更新 Drive
  2. public static void updateDrive() throws Exception {
  3. try {
  4. UpdateDriveRequestModel requestModel = new UpdateDriveRequestModel();
  5. UpdateDriveRequest updateDriveRequest = new UpdateDriveRequest();
  6. updateDriveRequest.driveId = "2801";
  7. updateDriveRequest.description = "changed_drive";
  8. updateDriveRequest.totalSize = 1000000L;
  9. requestModel.body = updateDriveRequest;
  10. UpdateDriveModel updateDriveResponse = client.updateDrive(requestModel0, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(updateDriveResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "requestId":"D88BC954-0BE8-4282-BDF3-6F964FC113DF",
  3. "creator":"6c23c**************9f5211",
  4. "description":"changed_drive",
  5. "domainId":"daily1405",
  6. "driveId":"1902",
  7. "driveName":"test_drive",
  8. "driveType":"normal",
  9. "owner":"6c23c9************5211",
  10. "relativePath":"/test_drive/",
  11. "status":"enabled",
  12. "storeId":"90fba27e9c40452d91d83b204aee1d9b",
  13. "totalSize":1000000,
  14. "usedSize":0
  15. }

删除drive

  • 以下代码用于创建Drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 删除 Drive
  2. public static void deleteDrive() throws Exception {
  3. try {
  4. DeleteDriveRequestModel requestModel = new DeleteDriveRequestModel();
  5. DeleteDriveRequest deleteDriveRequest = new DeleteDriveRequest();
  6. deleteDriveRequest.driveId= "1";
  7. requestModel.body = deleteDriveRequest;
  8. client.deleteDrive(requestModel, runtime);
  9. // 此接口不返回body
  10. } catch (TeaException e) {
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getCode());
  13. System.out.println(new Gson().toJson(e.getData()));
  14. }
  15. }

列举Stores

​ 说明:当前接口只支持accessToken调用, 请使用Accesstoken初始化客户端

  • 以下代码用于列举Stores,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public static void listStores() throws Exception {
  2. try {
  3. AdminListStoresRequestModel requestModel = new AdminListStoresRequestModel();
  4. AdminListStoresRequest listStoresRequest = new AdminListStoresRequest();
  5. requestModel.body = listStoresRequest;
  6. AdminListStoresModel listStoresResponse = client.adminListStores(requestModel, runtime);
  7. System.out.println(new Gson().toJson(listStoresResponse.body));
  8. } catch (TeaException e) {
  9. System.out.println(e.getMessage());
  10. System.out.println(e.getCode());
  11. System.out.println(new Gson().toJson(e.getData()));
  12. }
  13. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "accelerateEndpoint":"",
  5. "basePath":"",
  6. "bucket":"ccp-daily-test",
  7. "customizedEndpoint":"",
  8. "endpoint":"https://oss-cn-hangzhou.aliyuncs.com",
  9. "internalEndpoint":"",
  10. "ownership":"custom",
  11. "policy":"",
  12. "roleArn":"",
  13. "storeId":"90fba27e9c40452d91d83b204aee1d9b",
  14. "type":"oss"
  15. }
  16. ]
  17. }

OSSPath Share 相关 API

创建Share

  • 以下代码用于创建Share,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 格式化过期时间
  2. public static String getISOTime() {
  3. long currentTime = System.currentTimeMillis();
  4. currentTime += 30 * 60 * 1000;
  5. Date date = new Date(currentTime);
  6. TimeZone timeZone = TimeZone.getTimeZone("UTC");
  7. DateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
  8. dateFormat.setTimeZone(timeZone);
  9. String nowAsISO = dateFormat.format(date);
  10. return nowAsISO;
  11. }
  12. // 创建 Share
  13. public static void createShare() throws Exception {
  14. try {
  15. String nowAsISO = getISOTime();
  16. CreateShareRequestModel requestModel = new CreateShareRequestModel();
  17. CreateShareRequest createShareRequest = new CreateShareRequest();
  18. createShareRequest.shareFilePath = "/test_share/";
  19. createShareRequest.owner = userId;
  20. createShareRequest.shareName = "test_share";
  21. createShareRequest.permissions = new ArrayList<>(Arrays.asList("FILE.LIST"));
  22. createShareRequest.expiration = nowAsISO;
  23. createShareRequest.driveId = driveId;
  24. requestModel.body = createShareRequest;
  25. CreateShareModel createShareResponse = client.createShare(requestModel, runtime);
  26. // 打印结果
  27. System.out.println(new Gson().toJson(createShareResponse.body));
  28. } catch (TeaException e) {
  29. System.out.println(e.getMessage());
  30. System.out.println(e.getCode());
  31. System.out.println(new Gson().toJson(e.getData()));
  32. }
  33. }
  • 返回结果
  1. {
  2. "domainId":"daily1405",
  3. "shareId":"47057f7b-8182-4d2d-ba1a-09ede78782d7"
  4. }

列举Share

  • 以下代码用于列举Share,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 列举 Share
  2. public static void listShare() throws Exception {
  3. try {
  4. ListShareRequestModel requestModel = new ListShareRequestModel();
  5. ListShareRequest listShareRequest = new ListShareRequest();
  6. listShareRequest.owner = userId;
  7. requestModel.body = listShareRequest;
  8. ListShareModel listShareResponse = client.listShare(requestModel, runtime);
  9. // 打印结果
  10. System.out.println(new Gson().toJson(listShareResponse.body));
  11. } catch (TeaException e) {
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getCode());
  14. System.out.println(new Gson().toJson(e.getData()));
  15. }
  16. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "createdAt":"2019-10-28T06:22:21.163Z",
  5. "creator":"6c23c*************9f5211",
  6. "description":"changed_share",
  7. "domainId":"daily1405",
  8. "driveId":"1902",
  9. "expiration":"2019-10-28T06:52:21.139Z",
  10. "expired":false,
  11. "owner":"6c23c*****************3f9f5211",
  12. "permissions":[
  13. ],
  14. "shareFilePath":"/test_share/",
  15. "shareId":"47057f7b-8182-4d2d-ba1a-09ede78782d7",
  16. "shareName":"test_share",
  17. "status":"enabled",
  18. "updatedAt":"2019-10-28T06:22:21.163Z"
  19. }
  20. ],
  21. "nextMarker":""
  22. }

查询Share

  • 以下代码用于查询Share,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 查询Share
  2. public static void getShare() throws Exception {
  3. try {
  4. GetShareRequestModel requestModel = new GetShareRequestModel();
  5. GetShareRequest getShareRequest = new GetShareRequest();
  6. getShareRequest.shareId = shareID;
  7. requestModel.body = getShareRequest;
  8. GetShareModel getShareResponse = client.getShare(requestModel, runtime);
  9. // 打印结果
  10. System.out.println(new Gson().toJson(getShareResponse.body));
  11. } catch (TeaException e) {
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getCode());
  14. System.out.println(new Gson().toJson(e.getData()));
  15. }
  16. }
  • 返回结果
  1. {
  2. "createdAt":"2019-10-28T06:22:21.163Z",
  3. "creator":"6c23*************9f5211",
  4. "description":"",
  5. "domainId":"daily1405",
  6. "driveId":"1902",
  7. "expiration":"2019-10-28T06:52:21.139Z",
  8. "expired":false,
  9. "owner":"6c23c*************9f5211",
  10. "permissions":[
  11. "FILE.LIST"
  12. ],
  13. "shareFilePath":"/test_share/",
  14. "shareId":"47057f7b-8182-4d2d-ba1a-09ede78782d7",
  15. "shareName":"test_share",
  16. "status":"enabled",
  17. "updatedAt":"2019-10-28T06:22:21.163Z"
  18. }

更新Share

  • 以下代码用于更新Share,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 更新 Share
  2. public static void updateShare() throws Exception {
  3. try {
  4. UpdateShareRequestModel requestModel = new UpdateShareRequestModel();
  5. UpdateShareRequest updateShareRequest = new UpdateShareRequest();
  6. updateShareRequest.shareId = shareID;
  7. updateShareRequest.description = "changed_share";
  8. requestModel.body = updateShareRequest;
  9. UpdateShareModel updateShareResponse = client.updateShare(requestModel, runtime);
  10. // 打印结果
  11. System.out.println(new Gson().toJson(updateShareResponse.body));
  12. } catch (TeaException e) {
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getCode());
  15. System.out.println(new Gson().toJson(e.getData()));
  16. }
  17. }
  • 返回结果
  1. {
  2. "createdAt":"2019-10-28T06:22:21.163Z",
  3. "creator":"6c23c98********************f5211",
  4. "description":"changed_share",
  5. "domainId":"daily1405",
  6. "driveId":"1902",
  7. "expiration":"2019-10-28T06:52:21.139Z",
  8. "expired":false,
  9. "owner":"6c23c98********************f5211",
  10. "permissions":[
  11. "FILE.LIST"
  12. ],
  13. "shareFilePath":"/test_share/",
  14. "shareId":"47057f7b-8182-4d2d-ba1a-09ede78782d7",
  15. "shareName":"test_share",
  16. "status":"enabled",
  17. "updatedAt":"2019-10-28T06:22:21.163Z"
  18. }

删除Share

  • 以下代码用于删除Share,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 删除 Share
  2. public static void deleteShare() throws Exception {
  3. try {
  4. DeleteShareRequestModel requestModel = new DeleteShareRequestModel();
  5. DeleteShareRequest deleteShareRequest = new DeleteShareRequest();
  6. deleteShareRequest.shareId = shareID;
  7. requestModel.body = deleteShareRequest;
  8. DeleteShareModel deleteShareResponses = client.deleteShare(requestModel, runtime);
  9. //此接口不返回body
  10. } catch (TeaException e) {
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getCode());
  13. System.out.println(new Gson().toJson(e.getData()));
  14. }
  15. }

OSSPath File相关 API

创建File

  • 以下代码用于创建File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  • 说明: 此处创建File 还需要上传文件到OSS, 具体操作详见最佳实践。
  1. // 创建文件
  2. public static void createFile() throws Exception {
  3. try {
  4. OSSCreateFileRequestModel requestModel =new OSSCreateFileRequestModel();
  5. OSSCreateFileRequest ossCreateFileRequest = new OSSCreateFileRequest();
  6. ossCreateFileRequest.type = "file";
  7. ossCreateFileRequest.name = "a.txt";
  8. ossCreateFileRequest.driveId= "**";
  9. ossCreateFileRequest.parentFilePath = "/";
  10. ossCreateFileRequest.contentType = "text/plain";
  11. requestModel.body = ossCreateFileRequest;
  12. CreateFileModel ossCreateFileResponse = client.createFile(requestModel, runtime);
  13. // 打印结果
  14. System.out.println(new Gson().toJson(ossCreateFileResponse.body));
  15. } catch (TeaException e) {
  16. System.out.println(e.getMessage());
  17. System.out.println(e.getCode());
  18. System.out.println(new Gson().toJson(e.getData()));
  19. }
  20. }
  • 返回结果
  1. // 此处url省略部分,实际值详见接口调用返回的结果。
  2. {
  3. "domainId":"daily1405",
  4. "driveId":"1902",
  5. "filePath":"/a.txt",
  6. "partInfoList":[
  7. {
  8. "partNumber":1,
  9. "uploadUrl":"https://********.oss-cn-hangzhou.aliyuncs.***********8FB16"
  10. }
  11. ],
  12. "type":"file",
  13. "uploadId":"872F52602EB343D0ADCE3E75D008FB16"
  14. }

列举File

  • 以下代码用于列举File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 列举文件
  2. public static void listFile() throws Exception {
  3. try {
  4. OSSListFileRequestModel requestModel = new OSSListFileRequestModel();
  5. OSSListFileRequest ossListFileRequest = new OSSListFileRequest();
  6. ossListFileRequest.driveId= "***";
  7. ossListFileRequest.parentFilePath = folderPath;
  8. requestModel.body = ossListFileRequest;
  9. ListFileModel ossListFileResponse = client.listFile(requestModel, runtime);
  10. // 打印结果
  11. System.out.println(new Gson().toJson(ossListFileResponse.body));
  12. } catch (TeaException e) {
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getCode());
  15. System.out.println(new Gson().toJson(e.getData()));
  16. }
  17. }
  • 返回结果
  1. // 此处url省略部分,实际值详见接口调用返回的结果。
  2. {
  3. "items":[
  4. {
  5. "contentType":"",
  6. "domainId":"daily1405",
  7. "downloadUrl":"https://********.oss-cn-hangzhou.aliyuncs.***********8FB16",
  8. "driveId":"1902",
  9. "fileExtension":"txt",
  10. "filePath":"/test_folder/a.txt",
  11. "name":"a.txt",
  12. "parentFilePath":"/test_folder/",
  13. "size":8,
  14. "status":"available",
  15. "type":"file",
  16. "updatedAt":"2019-10-28T06:22:23Z",
  17. "url":"https://********.oss-cn-hangzhou.aliyuncs.***********8FB16"
  18. }
  19. ],
  20. "nextMarker":""
  21. }

查询File

  • 以下代码用于查询File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 查询File
  2. public static void getFile() throws Exception {
  3. try {
  4. OSSGetFileRequestModel requestModel = new OSSGetFileRequestModel();
  5. OSSGetFileRequest ossGetFileRequest = new OSSGetFileRequest();
  6. ossGetFileRequest.driveId= "2801";
  7. ossGetFileRequest.filePath = filePath;
  8. requestModel.body = ossGetFileRequest;
  9. GetFileModel ossGetFileResponse = client.getFile(requestModel, runtime);
  10. // 打印结果
  11. System.out.println(new Gson().toJson(ossGetFileResponse.body));
  12. } catch (TeaException e) {
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getCode());
  15. System.out.println(new Gson().toJson(e.getData()));
  16. }
  17. }
  • 返回结果
  1. {
  2. "contentType":"text/plain",
  3. "domainId":"daily1405",
  4. "downloadUrl":"https://********.oss-cn-hangzhou.aliyuncs.***********8FB16",
  5. "driveId":"1902",
  6. "fileExtension":"",
  7. "filePath":"/a.txt",
  8. "name":"a.txt",
  9. "parentFilePath":"/",
  10. "size":8,
  11. "status":"available",
  12. "type":"file",
  13. "updatedAt":"2019-10-28T06:22:23Z",
  14. "url":"https://********.oss-cn-hangzhou.aliyuncs.***********8FB16"
  15. }

移动File

  • 以下代码用于移动File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 移动 File
  2. public static void moveFile() throws Exception {
  3. try {
  4. OSSMoveFileRequestModel requestModel = new OSSMoveFileRequestModel();
  5. OSSMoveFileRequest ossMoveFileRequest = new OSSMoveFileRequest();
  6. ossMoveFileRequest.driveId= "***";
  7. ossMoveFileRequest.filePath = filePath;
  8. ossMoveFileRequest.toParentFilePath = folderPath;
  9. requestModel.body = ossMoveFileRequest;
  10. MoveFileModel ossMoveFileResponse = client.moveFile(requestModel, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(ossMoveFileResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "domainId":"daily1405",
  3. "driveId":"1902",
  4. "filePath":"/test_folder/a.txt"
  5. }

复制File

  • 以下代码用于复制File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 复制 File
  2. public static void copyFile() throws Exception {
  3. try {
  4. OSSCopyFileRequestModel requestModel = new OSSCopyFileRequestModel();
  5. OSSCopyFileRequest ossCopyFileRequest = new OSSCopyFileRequest();
  6. ossCopyFileRequest.filePath = movedFilePath;
  7. ossCopyFileRequest.driveId= "***";
  8. ossCopyFileRequest.toParentFilePath = "/";
  9. requestModel.body =ossCopyFileRequest;
  10. CopyFileModel ossCopyFileResponse = client.copyFile(requestModel, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(ossCopyFileResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "domainId":"daily1405",
  3. "driveId":"1902",
  4. "filePath":"/a.txt"
  5. }

获取File上传地址

  • 以下代码用于获取File上传地址,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 获取File上传地址
  2. public static void getFileUploadUrl() throws Exception {
  3. try {
  4. OSSGetUploadUrlRequestModel requestModel = new OSSGetUploadUrlRequestModel();
  5. UploadPartInfo uploadPartInfo = new UploadPartInfo();
  6. uploadPartInfo.partNumber = 1L;
  7. OSSGetUploadUrlRequest ossGetUploadUrlRequest = new OSSGetUploadUrlRequest();
  8. ossGetUploadUrlRequest.driveId = driveId;
  9. ossGetUploadUrlRequest.filePath = filePath;
  10. ossGetUploadUrlRequest.uploadId = uploadId;
  11. ossGetUploadUrlRequest.partInfoList = new ArrayList<>(Arrays.asList(uploadPartInfo));
  12. requestModel.body = ossGetUploadUrlRequest;
  13. GetUploadUrlModel ossGetUploadUrlResponse = client.getUploadUrl(requestModel, runtime);
  14. // 打印结果
  15. System.out.println(new Gson().toJson(ossGetUploadUrlResponse.body));
  16. } catch (TeaException e) {
  17. System.out.println(e.getMessage());
  18. System.out.println(e.getCode());
  19. System.out.println(new Gson().toJson(e.getData()));
  20. }
  21. }
  • 返回结果
  1. {
  2. "createAt":"2019-10-28T06:22:22.231Z",
  3. "domainId":"daily1405",
  4. "driveId":"1902",
  5. "filePath":"/a.txt",
  6. "partInfoList":[
  7. {
  8. "partNumber":1,
  9. "uploadUrl":"https://********.oss-cn-hangzhou.aliyuncs.***********8FB16"
  10. }
  11. ],
  12. "uploadId":"872F52602EB343D0ADCE3E75D008FB16"
  13. }

获取File下载地址

  • 以下代码用于获取File下载地址,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 获取File下载地址
  2. public static void getFileDownloadUrl() throws Exception {
  3. try {
  4. OSSGetDownloadUrlRequestModel requestModel = new OSSGetDownloadUrlRequestModel();
  5. OSSGetDownloadUrlRequest ossGetDownloadUrlRequest = new OSSGetDownloadUrlRequest();
  6. ossGetDownloadUrlRequest.driveId= "***";
  7. ossGetDownloadUrlRequest.filePath = filePath;
  8. ossGetDownloadUrlRequest.expireSec = 3600L;
  9. requestModel.body = ossGetDownloadUrlRequest;
  10. GetDownloadUrlModel ossGetDownloadUrlResponse = client.getDownloadUrl(requestModel, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(ossGetDownloadUrlResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "requestId":"6760BC8F-AA33-4862-AA26-0F8FA57EAF39",
  3. "expiration":"2019-10-28T07:22:24.044Z",
  4. "method":"GET",
  5. "url":"https://********.oss-cn-hangzhou.aliyuncs.***********8FB16"
  6. }

Complete File

  • 以下代码用于创建Complete File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  • 说明: 此处请求参数中的ETag是请求uploadUrl上传完成后从返回的Response Headers中获取的,详见最佳实践。
  1. // 合并File分片
  2. public static void completeFile() throws Exception {
  3. try {
  4. OSSCompleteFileRequestModel requestModel = new OSSCompleteFileRequestModel();
  5. UploadPartInfo uploadPartInfo1 = new UploadPartInfo();
  6. uploadPartInfo1.etag = etag;
  7. uploadPartInfo1.partNumber = 1L;
  8. OSSCompleteFileRequest ossCompleteFileRequest = new OSSCompleteFileRequest();
  9. ossCompleteFileRequest.driveId= "***";
  10. ossCompleteFileRequest.filePath = filePath;
  11. ossCompleteFileRequest.uploadId = newUploadId;
  12. ossCompleteFileRequest.partInfoList =new ArrayList<>(Arrays.asList(uploadPartInfo1));
  13. requestModel.body = ossCompleteFileRequest;
  14. CompleteFileModel ossCompleteFileResponse = client.completeFile(requestModel, runtime);
  15. // 打印结果
  16. System.out.println(new Gson().toJson(ossCompleteFileResponse.body));
  17. } catch (TeaException e) {
  18. System.out.println(e.getMessage());
  19. System.out.println(e.getCode());
  20. System.out.println(new Gson().toJson(e.getData()));
  21. }
  22. }
  • 返回结果
  1. {
  2. "contentType":"text/plain",
  3. "crc64Hash":"6668564720710875145",
  4. "domainId":"daily1405",
  5. "driveId":"1902",
  6. "fileExtension":"",
  7. "filePath":"/a.txt",
  8. "name":"a.txt",
  9. "parentFilePath":"/",
  10. "size":0,
  11. "status":"uploading",
  12. "type":"file",
  13. "uploadId":"872F52602EB343D0ADCE3E75D008FB16",
  14. "crc":"6668564720710875145"
  15. }

删除File

  • 以下代码用于删除File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 删除 file
  2. public static void deleteFile() throws Exception {
  3. try {
  4. OSSDeleteFileRequestModel requestModel = new OSSDeleteFileRequestModel();
  5. OSSDeleteFileRequest ossDeleteFileRequest = new OSSDeleteFileRequest();
  6. ossDeleteFileRequest.driveId= "***";
  7. ossDeleteFileRequest.filePath = filePath;
  8. requestModel.body = ossDeleteFileRequest;
  9. client.deleteFile(requestModel, runtime);
  10. // 此接口不返回body
  11. } catch (TeaException e) {
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getCode());
  14. System.out.println(new Gson().toJson(e.getData()));
  15. }
  16. }

列举Stores File

  • 以下代码用于列举Stores File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档.
  1. // 列举 Stores File
  2. public static void listStoreFiles() throws Exception {
  3. try {
  4. // list Stores
  5. AdminListStoresRequestModel requestModel = new AdminListStoresRequestModel();
  6. AdminListStoresRequest listStoresRequest = new AdminListStoresRequest();
  7. requestModel.body = listStoresRequest;
  8. AdminListStoresModel listStoresResponse = client.adminListStores(requestModel, runtime);
  9. String storeId = listStoresResponse.body.items.get(0).storeId;
  10. // list store_file
  11. ListStoreFileRequestModel requestModel = new ListStoreFileRequestModel();
  12. ListStoreFileRequest listStorageFileRequest = new ListStoreFileRequest();
  13. listStorageFileRequest.storeId = storeId;
  14. listStorageFileRequest.limit = 2L;
  15. requestModel.body = listStorageFileRequest;
  16. ListStorefileModel listStorageFileResponse = client.listStorefile(requestModel, runtime);
  17. // 打印结果
  18. System.out.println(new Gson().toJson(listStorageFileResponse.body));
  19. } catch (TeaException e) {
  20. System.out.println(e.getMessage());
  21. System.out.println(e.getCode());
  22. System.out.println(new Gson().toJson(e.getData()));
  23. }
  24. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "domainId":"",
  5. "name":"5733dbd6**********5c0",
  6. "parentFilePath":"/",
  7. "storeId":"90fba2***********e1d9b",
  8. "type":"folder"
  9. }
  10. ],
  11. "nextMarker":"5733db************86e75c0/"
  12. }

CCPPath Drive 相关API

创建drive

  • 以下代码用于创建Drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 创建 Drive
  2. public static void createDrive() throws Exception {
  3. try {
  4. CreateDriveRequestModel requestModel = new CreateDriveRequestModel();
  5. CreateDriveRequest createDriveRequest = new CreateDriveRequest();
  6. createDriveRequest.totalSize = 100000L;
  7. createDriveRequest.driveName = "test_drive";
  8. createDriveRequest.driveType = "normal";
  9. createDriveRequest.owner = userId;
  10. requestModel.body = createDriveRequest;
  11. CreateDriveModel createDriveResponse = client.createDrive(requestModel, runtime);
  12. // 打印结果
  13. System.out.println(new Gson().toJson(createDriveResponse.body));
  14. } catch (TeaException e) {
  15. System.out.println(e.getMessage());
  16. System.out.println(e.getCode());
  17. System.out.println(new Gson().toJson(e.getData()));
  18. }
  19. }
  • 返回结果
  1. {
  2. "domainId":"daily1404",
  3. "driveId":"603"
  4. }

列举drive

  • 以下代码用于列举drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 列举 Drive
  2. public static void listDrive() throws Exception {
  3. try {
  4. ListDriveRequestModel requestModel = new ListDriveRequestModel();
  5. ListDriveRequest listDriveRequest = new ListDriveRequest();
  6. listDriveRequest.limit = 1;
  7. listDriveRequest.owner = userId;
  8. requestModel.body = listDriveRequest;
  9. ListDrivesModel listDriveResponse = client.listDrives(requestModel, runtime);
  10. // 打印结果
  11. System.out.println(new Gson().toJson(listDriveResponse.body));
  12. } catch (TeaException e) {
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getCode());
  15. System.out.println(new Gson().toJson(e.getData()));
  16. }
  17. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "creator":"",
  5. "description":"",
  6. "domainId":"daily1404",
  7. "driveId":"603",
  8. "driveName":"test_drive",
  9. "driveType":"normal",
  10. "owner":"ldh",
  11. "relativePath":"",
  12. "status":"enabled",
  13. "storeId":"55ff60f575b24a8c97378f1e0a946904",
  14. "totalSize":100000,
  15. "usedSize":0
  16. }
  17. ],
  18. "nextMarker":""
  19. }

查询drive

  • 以下代码用于查询drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 查询 Drive
  2. public static void getDrive() throws Exception {
  3. try {
  4. GetDriveRequestModel requestModel = new GetDriveRequestModel();
  5. GetDriveRequest getDriveRequest = new GetDriveRequest();
  6. getDriveRequest.driveId = driveId;
  7. requestModel.body = getDriveRequest;
  8. GetDriveModel getDriveResponse = client.getDrive(requestModel, runtime);
  9. //打印结果
  10. System.out.println(new Gson().toJson(getDriveResponse.body));
  11. } catch (TeaException e) {
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getCode());
  14. System.out.println(new Gson().toJson(e.getData()));
  15. }
  16. }
  • 返回结果
  1. {
  2. "creator":"",
  3. "description":"",
  4. "domainId":"daily1404",
  5. "driveId":"603",
  6. "driveName":"test_drive",
  7. "driveType":"normal",
  8. "owner":"ldh",
  9. "relativePath":"",
  10. "status":"enabled",
  11. "storeId":"55ff60f575b24a8c97378f1e0a946904",
  12. "totalSize":100000,
  13. "usedSize":0
  14. }

更新drive

  • 以下代码用于更新drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 更新 Drive
  2. public static void updateDrive() throws Exception {
  3. try {
  4. UpdateDriveRequestModel requestModel = new UpdateDriveRequestModel();
  5. UpdateDriveRequest updateDriveRequest = new UpdateDriveRequest();
  6. updateDriveRequest.driveId = driveId;
  7. updateDriveRequest.description = "changed_drive";
  8. updateDriveRequest.totalSize = 1000000L;
  9. requestModel.body = updateDriveRequest;
  10. UpdateDriveModel updateDriveResponse = client.updateDrive(requestModel, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(updateDriveResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "creator":"",
  3. "description":"changed_drive",
  4. "domainId":"daily1404",
  5. "driveId":"603",
  6. "driveName":"test_drive",
  7. "driveType":"normal",
  8. "owner":"ldh",
  9. "relativePath":"",
  10. "status":"enabled",
  11. "storeId":"55ff60f575b24a8c97378f1e0a946904",
  12. "totalSize":1000000,
  13. "usedSize":0
  14. }

删除drive

  • 以下代码用于删除drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 删除 Drive
  2. public static void deleteDrive() throws Exception {
  3. try {
  4. DeleteDriveRequestModel requestModel = new DeleteDriveRequestModel();
  5. DeleteDriveRequest deleteDriveRequest = new DeleteDriveRequest();
  6. deleteDriveRequest.driveId = driveId;
  7. requestModel.body = deleteDriveRequest;
  8. DeleteDriveModel deleteDriveResponse = client.deleteDrive(requestModel, runtime);
  9. // 此接口不返回body
  10. } catch (TeaException e) {
  11. System.out.println(e.getMessage());
  12. System.out.println(e.getCode());
  13. System.out.println(new Gson().toJson(e.getData()));
  14. }
  15. }

CCPPath File 相关 API

创建File

  • 以下代码用于创建Drive,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 创建文件
  2. public static void createFile() throws Exception {
  3. try {
  4. CCPCreateFileRequestModel requestModel = new CCPCreateFileRequestModel();
  5. CCPCreateFileRequest ccpCreateFileRequest = new CCPCreateFileRequest();
  6. ccpCreateFileRequest.type = "file";
  7. ccpCreateFileRequest.name = "a.txt";
  8. ccpCreateFileRequest.driveId = driveId;
  9. ccpCreateFileRequest.parentFileId = "root";
  10. ccpCreateFileRequest.contentType = "text/plain";
  11. requestModel.body = ccpCreateFileRequest;
  12. CreateFileModel ccpCreateFileResponse = client.createFile(requestModel, runtime);
  13. // 打印结果
  14. System.out.println(new Gson().toJson(ccpCreateFileResponse.body));
  15. } catch (TeaException e) {
  16. System.out.println(e.getMessage());
  17. System.out.println(e.getCode());
  18. System.out.println(new Gson().toJson(e.getData()));
  19. }
  20. }
  • 返回结果
  1. {
  2. "domainId":"daily1404",
  3. "driveId":"603",
  4. "fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
  5. "parentFileId":"root",
  6. "partInfoList":[
  7. {
  8. "partNumber":1,
  9. "uploadUrl":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****F943"
  10. }
  11. ],
  12. "rapidUpload":false,
  13. "type":"file",
  14. "uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943"
  15. }

列举File

  • 以下代码用于列举File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 列举文件
  2. public static void listFile() throws Exception {
  3. try {
  4. CCPListFileRequestModel requestModel = new CCPListFileRequestModel();
  5. CCPListFileRequest ccpListFileRequest = new CCPListFileRequest();
  6. ccpListFileRequest.driveId = driveId;
  7. ccpListFileRequest.parentFileId = folderId;
  8. ccpListFileRequest.limit = 1L;
  9. requestModel.body = ccpListFileRequest;
  10. ListFileModel ccpListFileResponse = client.listFile(requestModel, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(ccpListFileResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
  5. "contentHashName":"sha1",
  6. "contentType":"",
  7. "createdAt":"2019-10-28T08:40:54.398Z",
  8. "domainId":"daily1404",
  9. "downloadUrl":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****.txt",
  10. "driveId":"603",
  11. "fileExtension":"txt",
  12. "fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
  13. "hidden":false,
  14. "name":"a.txt",
  15. "parentFileId":"5db6a996c7e9ae3a5e654a7798947b209989b963",
  16. "size":6,
  17. "starred":false,
  18. "status":"available",
  19. "type":"file",
  20. "updatedAt":"2019-10-28T08:40:55.398Z",
  21. "url":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****F943"
  22. }
  23. ],
  24. "nextMarker":""
  25. }

查询File

  • 以下代码用于查询File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 查询File
  2. public static void getFile() throws Exception {
  3. try {
  4. CCPGetFileRequestModel requestModel = new CCPGetFileRequestModel();
  5. CCPGetFileRequest ccpGetFileRequest = new CCPGetFileRequest();
  6. ccpGetFileRequest.driveId = driveId;
  7. ccpGetFileRequest.fileId = fileId;
  8. requestModel.body = ccpGetFileRequest;
  9. GetFileModel ccpGetFileResponse = client.getFile(requestModel, runtime);
  10. // 打印结果
  11. System.out.println(new Gson().toJson(ccpGetFileResponse.body));
  12. } catch (TeaException e) {
  13. System.out.println(e.getMessage());
  14. System.out.println(e.getCode());
  15. System.out.println(new Gson().toJson(e.getData()));
  16. }
  17. }
  • 返回结果
  1. {
  2. "contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
  3. "contentHashName":"sha1",
  4. "contentType":"text/plain",
  5. "crc64Hash":"318318745347147982",
  6. "createdAt":"2019-10-28T08:40:54.398Z",
  7. "domainId":"daily1404",
  8. "downloadUrl":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****F943.txt",
  9. "driveId":"603",
  10. "fileExtension":"txt",
  11. "fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
  12. "hidden":false,
  13. "name":"a.txt",
  14. "parentFileId":"root",
  15. "size":6,
  16. "starred":false,
  17. "status":"available",
  18. "type":"file",
  19. "updatedAt":"2019-10-28T08:40:55.398Z",
  20. "uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943",
  21. "url":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****F943"
  22. }

移动File

  • 以下代码用于移动File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 移动 File
  2. public static void moveFile() throws Exception {
  3. try {
  4. CCPMoveFileRequestModel requestModel = new CCPMoveFileRequestModel();
  5. CCPMoveFileRequest ccpMoveFileRequest = new CCPMoveFileRequest();
  6. ccpMoveFileRequest.driveId = driveId;
  7. ccpMoveFileRequest.fileId = fileId;
  8. ccpMoveFileRequest.toParentFileId = folderId;
  9. requestModel.body = ccpMoveFileRequest;
  10. MoveFileModel ccpMoveFileResponse = client.moveFile(requestModel, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(ccpMoveFileResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "domainId":"daily1404",
  3. "driveId":"603",
  4. "fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f"
  5. }

复制File

  • 以下代码用于复制File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 复制 File
  2. public static void copyFile() throws Exception {
  3. try {
  4. CCPCopyFileRequestModel requestModel = new CCPCopyFileRequestModel();
  5. CCPCopyFileRequest ccpCopyFileRequest = new CCPCopyFileRequest();
  6. ccpCopyFileRequest.fileId = fileId;
  7. ccpCopyFileRequest.driveId = driveId;
  8. ccpCopyFileRequest.toParentFileId = "root";
  9. requestModel.body = ccpCopyFileRequest;
  10. CopyFileModel ccpCopyFileResponse = client.copyFile(requestModel, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(ccpCopyFileResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "domainId":"daily1404",
  3. "driveId":"603",
  4. "fileId":"5db6a997ce31eb635f2e4f4c9163ec3bd10af459"
  5. }

获取File上传地址

  • 以下代码用于获取File上传地址,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 获取File上传地址
  2. public static void getFileUploadUrl() throws Exception {
  3. try {
  4. UploadPartInfo uploadPartInfo = new UploadPartInfo();
  5. uploadPartInfo.partNumber = 1L;
  6. CCPGetUploadUrlRequestModel requestModel = new CCPGetUploadUrlRequestModel();
  7. CCPGetUploadUrlRequest ccpGetUploadUrlRequest = new CCPGetUploadUrlRequest();
  8. ccpGetUploadUrlRequest.driveId = driveId;
  9. ccpGetUploadUrlRequest.fileId = fileId;
  10. ccpGetUploadUrlRequest.uploadId = uploadId;
  11. ccpGetUploadUrlRequest.partInfoList = new ArrayList<>(Arrays.asList(uploadPartInfo));
  12. requestModel.body = ccpGetUploadUrlRequest;
  13. GetUploadUrlModel ccpGetUploadUrlResponse = client.getUploadUrl(requestModel, runtime);
  14. // 打印结果
  15. System.out.println(new Gson().toJson(ccpGetUploadUrlResponse.body));
  16. } catch (TeaException e) {
  17. System.out.println(e.getMessage());
  18. System.out.println(e.getCode());
  19. System.out.println(new Gson().toJson(e.getData()));
  20. }
  21. }
  • 返回结果
  1. {
  2. "createAt":"2019-10-28T08:40:54.519Z",
  3. "domainId":"daily1404",
  4. "driveId":"603",
  5. "fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
  6. "partInfoList":[
  7. {
  8. "partNumber":1,
  9. "uploadUrl":"url":"https://****.oss-cn-hangzhou.aliyuncs.com/****wZM%3D"
  10. }
  11. ],
  12. "uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943"
  13. }

获取File下载地址

  • 以下代码用于获取File下载地,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 获取File下载地址
  2. public static void getFileDownloadUrl() throws Exception {
  3. try {
  4. CCPGetDownloadUrlRequestModel requestModel = new CCPGetDownloadUrlRequestModel();
  5. CCPGetDownloadUrlRequest ccpGetDownloadUrlRequest = new CCPGetDownloadUrlRequest();
  6. ccpGetDownloadUrlRequest.driveId = driveId;
  7. ccpGetDownloadUrlRequest.fileId = fileId;
  8. ccpGetDownloadUrlRequest.expireSec = 3600L;
  9. requestModel.body = ccpGetDownloadUrlRequest;
  10. GetDownloadUrlModel ccpGetDownloadUrlResponse = client.getDownloadUrl(requestModel, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(ccpGetDownloadUrlResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "expiration":"2019-10-28T09:40:55.716Z",
  3. "method":"GET",
  4. "url":"https://****.oss-cn-hangzhou.aliyuncs.com/****wZM%3D"
  5. }

Complete File

  • 以下代码用于Complete File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 合并File分片
  2. public static void completeFile() throws Exception {
  3. try {
  4. CCPCompleteFileRequestModel requestModel = new CCPCompleteFileRequestModel();
  5. CCPCompleteFileRequest ccpCompleteFileRequest = new CCPCompleteFileRequest();
  6. ccpCompleteFileRequest.driveId = driveId;
  7. ccpCompleteFileRequest.fileId = fileId;
  8. ccpCompleteFileRequest.uploadId = newUploadId;
  9. ccpCompleteFileRequest.partInfoList = new ArrayList<>(Arrays.asList(uploadPartInfo1));
  10. requestModel.body = ccpCompleteFileRequest;
  11. CompleteFileModel ccpCompleteFileResponse = client.completeFile(requestModel, runtime);
  12. // 打印结果
  13. System.out.println(new Gson().toJson(ccpCompleteFileResponse.body));
  14. } catch (TeaException e) {
  15. System.out.println(e.getMessage());
  16. System.out.println(e.getCode());
  17. System.out.println(new Gson().toJson(e.getData()));
  18. }
  19. }
  • 返回结果
  1. {
  2. "contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
  3. "contentHashName":"sha1",
  4. "contentType":"text/plain",
  5. "crc64Hash":"318318745347147982",
  6. "createdAt":"2019-10-28T08:40:54.398Z",
  7. "domainId":"daily1404",
  8. "driveId":"603",
  9. "fileExtension":"txt",
  10. "fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
  11. "hidden":false,
  12. "name":"a.txt",
  13. "parentFileId":"root",
  14. "size":6,
  15. "starred":false,
  16. "status":"available",
  17. "type":"file",
  18. "updatedAt":"2019-10-28T08:40:55.398Z",
  19. "uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943",
  20. "crc":""
  21. }

更新File

  • 以下代码用于更新File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 更新 file
  2. public static void updateFile() throws Exception {
  3. try {
  4. CCPUpdateFileMetaRequestModel requestModel = new CCPUpdateFileMetaRequestModel();
  5. CCPUpdateFileMetaRequest ccpUpdateFileMetaRequest = new CCPUpdateFileMetaRequest();
  6. ccpUpdateFileMetaRequest.fileId = fileId;
  7. ccpUpdateFileMetaRequest.description = "changed_file";
  8. ccpUpdateFileMetaRequest.driveId = driveId;
  9. requestModel.body = ccpUpdateFileMetaRequest;
  10. UpdateFileModel ccpUpdateFileMetaResponse = client.updateFile(requestModel, runtime);
  11. // 打印结果
  12. System.out.println(new Gson().toJson(ccpUpdateFileMetaResponse.body));
  13. } catch (TeaException e) {
  14. System.out.println(e.getMessage());
  15. System.out.println(e.getCode());
  16. System.out.println(new Gson().toJson(e.getData()));
  17. }
  18. }
  • 返回结果
  1. {
  2. "contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
  3. "contentHashName":"sha1",
  4. "contentType":"text/plain",
  5. "crc64Hash":"318318745347147982",
  6. "createdAt":"2019-10-28T08:40:54.398Z",
  7. "description":"changed_file",
  8. "domainId":"daily1404",
  9. "downloadUrl":"https://******.oss-cn-hangzhou.aliyuncs.com/5****a.txt",
  10. "driveId":"603",
  11. "fileExtension":"txt",
  12. "fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
  13. "hidden":false,
  14. "name":"a.txt",
  15. "parentFileId":"5db6a996c7e9ae3a5e654a7798947b209989b963",
  16. "size":6,
  17. "starred":false,
  18. "status":"available",
  19. "type":"file",
  20. "updatedAt":"2019-10-28T08:40:55.398Z",
  21. "uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943",
  22. "url":"https://****.oss-cn-hangzhou.aliyuncs.com/****wZM%3D"
  23. }

搜索File

  • 以下代码用于搜索File,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 搜索 file
  2. public static void searchFile() throws Exception {
  3. try {
  4. CCPSearchFileRequestModel requestModel = new CCPSearchFileRequestModel();
  5. CCPSearchFileRequest ccpSearchFileRequest = new CCPSearchFileRequest();
  6. ccpSearchFileRequest.driveId = driveId;
  7. ccpSearchFileRequest.limit = 3;
  8. ccpSearchFileRequest.orderBy = "type DESC";
  9. ccpSearchFileRequest.query = "file_extension in [\"txt\"]";
  10. requestModel.body = ccpSearchFileRequest;
  11. SearchFileModel ccpSearchFileResponse = client.searchFile(requestModel, runtime);
  12. // 打印结果
  13. System.out.println(new Gson().toJson(ccpSearchFileResponse.body));
  14. } catch (TeaException e) {
  15. System.out.println(e.getMessage());
  16. System.out.println(e.getCode());
  17. System.out.println(new Gson().toJson(e.getData()));
  18. }
  19. }
  • 返回结果
  1. {
  2. "items":[
  3. {
  4. "contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
  5. "contentHashName":"sha1",
  6. "contentType":"text/plain",
  7. "crc64Hash":"318318745347147982",
  8. "createdAt":"2019-10-28T08:40:54.398Z",
  9. "description":"changed_file",
  10. "domainId":"daily1404",
  11. "downloadUrl":"https://************.oss-cn-hangzhou.aliyuncs.com/***a.txt",
  12. "driveId":"603",
  13. "fileExtension":"txt",
  14. "fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
  15. "hidden":false,
  16. "name":"a.txt",
  17. "parentFileId":"5db6a996c7e9ae3a5e654a7798947b209989b963",
  18. "size":6,
  19. "starred":false,
  20. "status":"available",
  21. "type":"file",
  22. "updatedAt":"2019-10-28T08:40:55.398Z",
  23. "uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943",
  24. "url":"https://****.oss-cn-hangzhou.aliyuncs.com/****ZM%3D"
  25. }
  26. ],
  27. "nextMarker":""
  28. }

删除File

  • 以下代码用于删除file,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. // 删除 file
  2. public static void deleteFile() throws Exception {
  3. try {
  4. CCPDeleteFileRequestModel requestModel = new CCPDeleteFileRequestModel();
  5. CCPDeleteFileRequest ccpDeleteFileRequest = new CCPDeleteFileRequest();
  6. ccpDeleteFileRequest.driveId = driveId;
  7. ccpDeleteFileRequest.fileId = fileId;
  8. requestModel.body = ccpDeleteFileRequest;
  9. DeleteFileModel deleteFileResponse = client.deleteFile(requestModel, runtime);
  10. System.out.println(new Gson().toJson(deleteFileResponse.body));
  11. } catch (TeaException e) {
  12. System.out.println(e.getMessage());
  13. System.out.println(e.getCode());
  14. System.out.println(new Gson().toJson(e.getData()));
  15. }
  16. }

批量操作

  • 以下代码用于批量操作,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void batch() throws Exception {
  2. try {
  3. CCPBatchRequestModel requestModel = new CCPBatchRequestModel();
  4. CCPBatchRequest ccpBatchRequest = new CCPBatchRequest();
  5. ccpBatchRequest.resource = "file";
  6. BatchSubRequest batchSubRequest = new BatchSubRequest();
  7. Map<String, Object> bodyMap = new HashMap<>();
  8. Map<String, Object> headerMap = new HashMap<>();
  9. bodyMap.put("drive_id", "1");
  10. bodyMap.put("file_id", "5e7e292b58fe324cd****7fce0f1c");
  11. bodyMap.put("description", "changed_file");
  12. headerMap.put("authorization", "eyJhbGciOiJSUz******5cCI6IkpXVCJ9");
  13. batchSubRequest.body = bodyMap;
  14. batchSubRequest.url = "/file/update";
  15. batchSubRequest.method = "POST";
  16. batchSubRequest.headers = headerMap;
  17. batchSubRequest.id = "uuid";
  18. ccpBatchRequest.requests = new ArrayList<>(Arrays.asList(batchSubRequest));
  19. requestModel.body = ccpBatchRequest;
  20. OperationModel response = client.operation(requestModel, runtime);
  21. System.out.println(new Gson().toJson(response.body));
  22. } catch (TeaException e) {
  23. System.out.println(e.getMessage());
  24. }
  25. }
  • 返回结果
  1. {
  2. "responses":[
  3. {
  4. "status":200,
  5. "body":{
  6. "file_extension":"txt",
  7. "updated_at":"2020-03-30T08:15:58.267Z",
  8. "content_hash":"FAA12FD40AAC1F492082C90C2CD6C03B9ABDB826",
  9. "domain_id":"hz22",
  10. "size":36,
  11. "category":"doc",
  12. "content_hash_name":"sha1",
  13. "download_url":"https://ccp-daily-default-c**n-han***Z8bG%2B9C4VII%3D",
  14. "crc64_hash":"13138712399852734283",
  15. "drive_id":"1",
  16. "hidden":false,
  17. "type":"file",
  18. "parent_file_id":"root",
  19. "status":"available",
  20. "description":"changed_file",
  21. "encrypt_mode":"none",
  22. "file_id":"5e81aabdae****d9836b36",
  23. "content_type":"application/oct-stream",
  24. "name":"testDJw8oWE6ef9464f66e5034f69aafd57cb2879170b.txt",
  25. "url":"https://ccp-daily-default-c**n-han***Z8bG%2B9C4VII%3D",
  26. "created_at":"2020-03-30T08:15:57.361Z",
  27. "upload_id":"DFD1DA39317F45EC8534FEA57AE420D1",
  28. "starred":false
  29. },
  30. "id":"624830fa2c2347be8c0d8afc76faa04d"
  31. }
  32. ]
  33. }

获取file已经上传的分片

  • 以下代码用于获取file已经上传的分片,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void listUploadedPart() throws Exception {
  2. try {
  3. CCPListUploadedPartRequestModel requestModel = new CCPListUploadedPartRequestModel();
  4. CCPListUploadedPartRequest ccpListUploadedPartRequest = new CCPListUploadedPartRequest();
  5. ccpListUploadedPartRequest.driveId = "1";
  6. ccpListUploadedPartRequest.fileId = "****";
  7. ccpListUploadedPartRequest.uploadId = "****";
  8. requestModel.body = ccpListUploadedPartRequest;
  9. ListUploadedPartsModel response = client.listUploadedParts(requestModel, runtime);
  10. System.out.println(new Gson().toJson(response.body));
  11. } catch (TeaException e) {
  12. System.out.println(e.getMessage());
  13. }
  14. }
  • 返回结果
  1. {
  2. "drive_id" : "1",
  3. "file_id" : "5d5b846942cf94fa72324c14a4bda34e81da635d",
  4. "limit" : 1,
  5. "part_number_marker" : 1,
  6. "upload_id" : "00668396C0814D818D90F0A92B04B355"
  7. }

获取异步信息

  • 以下代码用于获取异步信息,此处的示例,目的是展示关键参数 ,其他参数请查看官方文档。
  1. public void getAsyncTask() throws Exception {
  2. try {
  3. CCPGetAsyncTaskRequestModel requestModel = new CCPGetAsyncTaskRequestModel();
  4. CCPGetAsyncTaskRequest getAsyncTaskRequest = new CCPGetAsyncTaskRequest();
  5. getAsyncTaskRequest.asyncTaskId = "***";
  6. requestModel.body = getAsyncTaskRequest;
  7. GetAsyncTaskInfoModel response = client.getAsyncTaskInfo(requestModel, runtime);
  8. System.out.println(new Gson().toJson(response.headers));
  9. } catch (TeaException e) {
  10. System.out.println(e.getMessage());
  11. }
  12. }
  • 返回结果
  1. {
  2. "async_task_id" : "000e89fb-cf8f-11e9-8ab4-b6e980803a3b",
  3. "message" : "task is running",
  4. "state" : "success"
  5. }

创建RAM子用户(获取AK,SK)

  1. 注册阿里云账号,详见阿里云账号注册流程
  2. 开启访问控制服务,详见RAM访问控制,并根据提示操作。
  3. 创建RAM子用户,并获取AK,SK。详见服务端调用接口接入。SK要注意保密不要泄露。

创建APP(获取ClientID, ClientSecret)

  1. 首先,您需要开通内容协作平台(CCP)服务。如果没有开通,请到产品详情页面开通 。
  2. 您需要在CCP官网控制台创建一个域(Domain) 。详见创建CCPath域实例和创建OSSPath域实例
  3. 创建APP,选择类型为”Web服务应用”。确定APP的访问Scope: 支持的Scope列表, 这个Scope要在用户授权页面展示。创建完成,可以得到APP ID(ClientID) 和 Secret(ClientSecret)。这个是授权认证的凭证,Secret要注意保密不要泄露。

CCPPath 上传文件

  1. import com.aliyun.ccp.ccpclient.Client;
  2. import com.aliyun.ccp.ccpclient.models.*;
  3. import com.aliyun.tea.TeaException;
  4. import com.google.gson.Gson;
  5. import okhttp3.*;
  6. import java.util.*;
  7. public class Demo {
  8. private static Client client;
  9. private static RuntimeOptions runtime;
  10. public static void main(String[] args) throws Exception{
  11. createClient();
  12. createFile();
  13. }
  14. public static void createClient() throws Exception {
  15. Config config = new Config();
  16. config.domainId= "your domain id";
  17. config.protocol = "https";
  18. config.accessKeyId = "your accessKeyId";
  19. config.accessKeySecret = "your accessKeySecret";
  20. client = new Client(config);
  21. runtime = new RuntimeOptions();
  22. }
  23. public static void createFile() throws Exception{
  24. try{
  25. System.out.println("-------------create file----------------");
  26. CCPCreateFileRequestModel requestModel = new CCPCreateFileRequestModel();
  27. CCPCreateFileRequest ccpCreateFileRequest = new CCPCreateFileRequest();
  28. ccpCreateFileRequest.type = "file";
  29. ccpCreateFileRequest.name = "a.txt";
  30. ccpCreateFileRequest.driveId = "1";
  31. ccpCreateFileRequest.parentFileId = "root";
  32. ccpCreateFileRequest.contentType = "text/plain";
  33. requestModel.body = ccpCreateFileRequest;
  34. CreateFileModel ccpCreateFileResponse = client.createFile(requestModel, runtime);
  35. System.out.println(new Gson().toJson(ccpCreateFileResponse.body));
  36. String uploadId = ccpCreateFileResponse.body.uploadId;
  37. String fileId = ccpCreateFileResponse.body.fileId;
  38. String uploadUrl = ccpCreateFileResponse.body.partInfoList.get(0).uploadUrl;
  39. // upload file
  40. System.out.println("-------------upload file----------------");
  41. Request.Builder requestBuilder = new Request.Builder();
  42. RequestBody body = RequestBody.create(MediaType.parse(""), "123456");
  43. requestBuilder.url(uploadUrl);
  44. requestBuilder.put(body);
  45. Request request = requestBuilder.build();
  46. OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
  47. Response response = okHttpClient.newCall(request).execute();
  48. String etag = response.headers().get("ETag");
  49. System.out.println();
  50. // complete file
  51. System.out.println("-------------complete file----------------");
  52. UploadPartInfo uploadPartInfo1 = new UploadPartInfo();
  53. uploadPartInfo1.etag = etag;
  54. uploadPartInfo1.partNumber = 1L;
  55. CCPCompleteFileRequestModel requestModel1 = new CCPCompleteFileRequestModel();
  56. CCPCompleteFileRequest ccpCompleteFileRequest = new CCPCompleteFileRequest();
  57. ccpCompleteFileRequest.driveId = "1";
  58. ccpCompleteFileRequest.fileId = fileId;
  59. ccpCompleteFileRequest.uploadId = uploadId;
  60. ccpCompleteFileRequest.partInfoList = new ArrayList<>(Arrays.asList(uploadPartInfo1));
  61. requestModel1.body = ccpCompleteFileRequest;
  62. CompleteFileModel ccpCompleteFileResponse = client.completeFile(requestModel1, runtime);
  63. System.out.println(new Gson().toJson(ccpCompleteFileResponse.body));
  64. }catch (TeaException e) {
  65. System.out.println(e.getMessage());
  66. System.out.println(e.getCode());
  67. System.out.println(new Gson().toJson(e.getData()));
  68. }
  69. }
  70. }