目前,PDS Java SDK 支持 J2SE 6.0 及以上的 Java 运行环境,您可以从 Java 官方网站 下载并按说明安装 Java 开发环境。
安装完 Java 开发环境后,您需要安装PDS SDK,将下面的依赖加入 pom.xml 。
StandardMode
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-sdk-pds</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>credentials-java</artifactId>
<version>0.1.0</version>
</dependency>
注意:请关注 Git Hub提供的最新版本,查看相关功能并选择使用。
使用前提是您已经开通PDS服务, 并且在控制台创建了域实例。参见快速搭建云盘服务。之后您可以按需初始化StandardModeClient 或者 HostingModeClient。
AK, SK 的获取详见 密钥管理页面。选择一对用于 SDK 的访问密钥对。如果没有,请创建一对新访问密钥,且保证它处于启用状态。有关如何创建访问密钥,参见 创建访问密钥。
import com.aliyun.pds.client.Client;
import com.aliyun.pds.client.models.*;
public class Demo {
private static Client client;
public static void createClient() throws IllegalAccessException {
Config config = new Config();
config.domainId = "your domainId";
config.protocol = "https";
config.accessKeyId = System.getenv("accessKeyId");
config.accessKeySecret = System.getenv("accessKeySecret");
client = new Client(config);
}
}
clientId, clientSecret 的获取详见应用接入指南。
import com.aliyun.pds.client.Client;
import com.aliyun.pds.client.models.*;
public class Demo {
private static Client client;
public static void createClient() throws IllegalAccessException {
Config config = new Config();
config.domainId = "your domainId";
config.protocol = "https";
config.clientId = System.getenv("clientId");
config.clientSecret = System.getenv("clientSecret");
config.accessToken = System.getenv("accessToken");
config.refreshToken = System.getenv("refreshToken");
config.expireTime = System.getenv("expireTime");
client = new Client(config);
}
}
注意:AK & SK 模式 和 Access Token & Refresh Token 模式 同时只能存在一种
public static void getCaptcha() throws Exception {
try {
GetCaptchaRequest getCaptchaRequest = new GetCaptchaRequest();
getCaptchaRequest.appId = "***********";
GetCaptchaModel captcha = client.getCaptcha(getCaptchaRequest);
// 打印结果
System.out.println(new Gson().toJson(captcha.body.captcha));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(e.getData());
}
}
{
"captcha":"iVBORw0KGgoAAAANSUhEUgAAAFAAAAAaCAIAAACvsEzwAAABFUlEQVR42u3YwQ7CIAwGYOKDaLya7OBL+BDePRoT4/vPJSSEjFJ+2oEIW3oy0PHRDnVmHuwyO3gH93J9Xm85+PA4+REOmKYLGbGE5/vVBn/f2/O4hMZs9FrSjIMdtVEwKSSLTG7Bb8HZLc30MALmB7QLlmkHAiPa3sDIsE7AYHkbAtvvaw0YHNlQhRezZeee0nh5BWC/EkVamjHHtqAoWGbOe4ZtqZFfWrmHcxhIhYuD3Z2S2gpgmVn450G2u8i5mOzn1aFlV7LKwCQ0FRaqTOWcsSPazvUzZIPJbStaahCMT48lNIjHD0GpkQzKftkMzK9e8/yHecLPwZ0ihZuBK7yFKTq9uXdamp7/M7Df22JPcsxw4C/GgzEzOWpc1QAAAABJRU5ErkJggg==",
"captchaFormat":"png",
"captchaId":"f644d0b2a7d21a3caddb17377c90c28e8DPXYUIfvs3"
}
public void getMNSCode() throws Exception {
try {
MobileSendSmsCodeRequest sendSmsCodeRequest = new MobileSendSmsCodeRequest();
sendSmsCodeRequest.appId = "your app id";
sendSmsCodeRequest.phoneNumber = "13**********5";
sendSmsCodeRequest.type = "change_password";
MobileSendSmsCodeModel response = client.mobileSendSmsCode(sendSmsCodeRequest);
System.out.println(new Gson().toJson(response.body));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
{
"smsCodeId":"b40bba70b37d74**********************6j3IW7HP"
}
public void checkMobileIsExist() throws Exception {
try {
MobileCheckExistRequest checkExistRequest = new MobileCheckExistRequest();
checkExistRequest.appId = "your app id";
checkExistRequest.phoneNumber = "13*****25";
CheckExistModel checkExistResponse = client.checkExist(checkExistRequest);
System.out.println(new Gson().toJson(checkExistResponse.body));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
{
"isExist":true,
"phoneNumber":"13****25"
}
public void register() throws Exception {
try {
MobileRegisterRequest registerRequest = new MobileRegisterRequest();
registerRequest.appId = "your app id";
registerRequest.phoneNumber = "132****225";
registerRequest.smsCode = "0****0";
registerRequest.smsCodeId = "674e************JRuoQgRu0R";
RegisterModel tokenResponse = client.register(registerRequest);
System.out.println(new Gson().toJson(tokenResponse.body));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
{
"access_token": "eyJhbGc***************iOiJSUzI1NiI",
"refresh_token": "fvw1FLZ************tGjXxJl",
"expires_in": 7200,
"token_type": "Bearer",
"user_id": "6c23c98d3***************3f9f5211",
"user_name": "132******225",
"avatar": "",
"nick_name": "1329*****225",
"default_drive_id": "",
"role": "admin",
"expire_time": "2019-10-30T11:44:24Z",
"state": "",
"exist_link": [],
"need_link": false,
"user_data": {}
}
public void mnsLogin() throws Exception {
try {
// mns login
MobileLoginRequest mobileLoginRequest = new MobileLoginRequest();
mobileLoginRequest.appId = "your app id";
mobileLoginRequest.phoneNumber = "132**********#=&";
mobileLoginRequest.smsCode = "123456";
mobileLoginRequest.smsCodeId = "your sms code";
LoginModel tokenResponse = client.login(mobileLoginRequest);
System.out.println(new Gson().toJson(tokenResponse));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
public void setPassWord() throws Exception {
try {
DefaultSetPasswordRequest setPasswordRequest = new DefaultSetPasswordRequest();
setPasswordRequest.appId = "your app id";
setPasswordRequest.newPassword = "1234567";
setPasswordRequest.state = "";
client.setPassword(setPasswordRequest);
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
// 密码登录
public static void passwordLogin() throws Exception {
try {
MobileLoginRequest mobileLoginRequest = new MobileLoginRequest();
mobileLoginRequest.appId = "your app id";
mobileLoginRequest.phoneNumber = "132******25";
mobileLoginRequest.password = "123********456";
LoginModel tokenResponse = client.login(mobileLoginRequest);
System.out.println(new Gson().toJson(tokenResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(e.getData());
}
}
public void changePassWord() throws Exception {
try {
DefaultChangePasswordRequest changePasswordRequest = new DefaultChangePasswordRequest();
changePasswordRequest.appId = "your app id";
changePasswordRequest.phoneNumber = "13*****25";
changePasswordRequest.newPassword = "12*****9";
changePasswordRequest.state = "6*****73";
changePasswordRequest.encryptedKey = "Your EncryptedKey";
client.changePassword(changePasswordRequest);
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
public void getTokenByRefreshToken() throws Exception {
try {
TokenRequest tokenRequest = new TokenRequest();
tokenRequest.appId = "your app id";
tokenRequest.grantType = "refresh_token";
tokenRequest.refreshToken = "CzuJktQK*********TAVTJorJa";
AccountTokenModel tokenResponse = client.accountToken(tokenRequest);
System.out.println(new Gson().toJson(tokenResponse));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
}
}
public void getAccessTokenByLinkInfo() throws Exception {
try {
// 此接口需要ak,sk调用, 请使用ak, sk初始化客户端
GetAccessTokenByLinkInfoRequest getAccessTokenByLinkInfoRequest = new GetAccessTokenByLinkInfoRequest();
getAccessTokenByLinkInfoRequest.identity = "132********25";
getAccessTokenByLinkInfoRequest.type = "mobile";
GetAccessTokenByLinkInfoModel tokenResponse = client.getAccessTokenByLinkInfo(getAccessTokenByLinkInfoRequest);
System.out.println(new Gson().toJson(tokenResponse.body));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
public void getLinkInfoByUserId() throws Exception {
try {
// 此接口需要ak,sk调用, 请使用ak, sk初始化客户端
GetLinkInfoByUserIDRequest linkInfoByUserIDRequest = new GetLinkInfoByUserIDRequest();
linkInfoByUserIDRequest.userId = "6c23*********5211";
GetLinkInfoByUserIdModel listResponse = client.getLinkInfoByUserId(linkInfoByUserIDRequest);
System.out.println(new Gson().toJson(listResponse.body));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
{
"items":[
{
"authenticationType":"mobile",
"createdAt":1571905906341,
"domainId":"daily1405",
"identity":"13******225",
"lastLoginTime":1571905906341,
"status":"normal",
"userId":"6c23c9******3f9f5211"
}
]
}
public void getLinkInfo() throws Exception {
try {
// 此接口需要ak,sk调用, 请使用ak, sk初始化客户端
GetByLinkInfoRequest getByLinkInfoRequest = new GetByLinkInfoRequest();
getByLinkInfoRequest.identity = "adsfqwrsfad";
getByLinkInfoRequest.type = "ding";
GetLinkInfoModel linkInfoResponse = client.getLinkInfo(getByLinkInfoRequest);
System.out.println(new Gson().toJson(linkInfoResponse.body));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
{
"authenticationType":"ding",
"createdAt":1572427460313,
"domainId":"daily1405",
"identity":"adsfqwrsfad",
"lastLoginTime":1572427460313,
"status":"wait_link",
"userId":"6c23c98*****7d8b3f9f5211"
}
public void userLinkInfo() throws Exception {
try {
// 此接口需要ak,sk调用, 请使用ak, sk初始化客户端
AccountLinkRequest linkInfo = new AccountLinkRequest();
linkInfo.type = "taobao";
linkInfo.identity = "1234";
linkInfo.userId = "1eb15*************eff97708cb";
linkInfo.status ="wait_link";
LinkModel tokenResponse = client.link(linkInfo);
System.out.println(new Gson().toJson(tokenResponse.body));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
{
"avatar":"",
"defaultDriveId":"",
"existLink":[
{
"identity":"13*****225",
"type":"mobile"
}
],
"expireTime":"",
"expiresIn":300,
"needLink":true,
"nickName":"",
"refreshToken":"",
"role":"",
"state":"",
"tokenType":"Bearer",
"userId":"",
"userName":""
}
public void cancelLink() throws Exception {
try {
CancelLinkRequest cancelLinkRequest = new CancelLinkRequest();
cancelLinkRequest.temporaryToken = "eyJhbGciOiJSUzI1N*****pwc";
CancelLinkModel tokenResponse = client.cancelLink(cancelLinkRequest);
System.out.println(new Gson().toJson(tokenResponse.body));;
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
public void confirmLink() throws Exception {
try {
ConfirmLinkRequest confirmLinkRequest = new ConfirmLinkRequest();
confirmLinkRequest.temporaryToken = "eyJhbGciOiJSUzI1NiIsI(***qE";
ConfirmLinkModel tokenResponse = client.confirmLink(confirmLinkRequest);
System.out.println(new Gson().toJson(tokenResponse));
} catch (TeaException e) {
System.out.println(e.getCode());
System.out.println(e.getMessage());
System.out.println(e.getData());
}
}
// 创建User
public static void createUser() throws Exception {
try {
CreateUserRequest createUserRequest = new CreateUserRequest();
createUserRequest.userId = "test_user";
createUserRequest.role = "user";
createUserRequest.description = "123";
CreateUserModel createUserResponse = client.createUser(createUserRequest);
System.out.println(new Gson().toJson(createUserResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
{
"avatar":"",
"createdAt":1572225460185,
"defaultDriveId":"",
"description":"",
"domainId":"daily1405",
"email":"",
"nickName":"",
"phone":"",
"role":"user",
"status":"enabled",
"updatedAt":0,
"userId":"test_user",
"userName":"test_user"
}
//获取User
public static void getUser() throws Exception {
try {
GetUserRequest getUserRequest = new GetUserRequest();
getUserRequest.userId = "test_user";
GetUserModel getUserResponse = client.getUser(getUserRequest);
System.out.println(new Gson().toJson(getUserResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
{
"avatar":"",
"createdAt":1572226149810,
"defaultDriveId":"",
"description":"",
"domainId":"daily1405",
"email":"",
"nickName":"",
"phone":"",user
"role":"user",
"status":"enabled",
"updatedAt":0,
"userId":"test_user",
"userName":"test_user"
}
//列举User
public static void listUsers() throws Exception {
try {
ListUserRequest listUserRequest = new ListUserRequest();
listUserRequest.limit = 10;
ListUsersModel listUserResponse = client.listUsers(listUserRequest);
System.out.println(new Gson().toJson(listUserResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
{
"items":[
{
"avatar":"",
"createdAt":1571903980532,
"defaultDriveId":"",
"description":"",
"domainId":"daily1405",
"email":"",
"nickName":"xxxxxx",
"phone":"",
"role":"user",
"status":"enabled",
"updatedAt":1571903980532,
"userId":"1eb15a*****************8cb",
"userName":"xxxxxx"
},
{
"avatar":"",
"createdAt":1571915575499,
"defaultDriveId":"",
"description":"",
"domainId":"daily1405",
"email":"",
"nickName":"xxxxxx",
"phone":"",
"role":"user",
"status":"enabled",
"updatedAt":1571915575499,
"userId":"51901a4************dbf5",
"userName":"xxxxxx"
},
{
"avatar":"",
"createdAt":1571903776751,
"defaultDriveId":"",
"description":"",
"domainId":"daily1405",
"email":"",
"nickName":"xxxxxx",
"phone":"",
"role":"user",
"status":"enabled",
"updatedAt":1571903776751,
"userId":"621a3c***************8ecd",
"userName":"xxxxxx"
},
{
"avatar":"",
"createdAt":1571905906346,
"defaultDriveId":"",
"description":"",
"domainId":"daily1405",
"email":"",
"nickName":"1329***25",
"phone":"132****25",
"role":"admin",
"status":"enabled",
"updatedAt":1571907859554,
"userId":"6c23c98****************f5211",
"userName":"132**********5"
},
{
"avatar":"",
"createdAt":1572226835585,
"defaultDriveId":"",
"description":"",
"domainId":"daily1405",
"email":"",
"nickName":"",
"phone":"",
"role":"admin",
"status":"enabled",
"updatedAt":0,
"userId":"xxxxxx",
"userName":"xxxxxx"
},
{
"avatar":"",
"createdAt":1571887988846,
"defaultDriveId":"",
"description":"",
"domainId":"daily1405",
"email":"",
"nickName":"superadmin",
"phone":"",
"role":"superadmin",
"status":"enabled",
"updatedAt":0,
"userId":"superadmin",
"userName":"superadmin"
}
],
"nextMarker":""
}
//更新User
public static void updateUser() throws Exception {
try {
UpdateUserRequest updateUserRequest = new UpdateUserRequest();
updateUserRequest.description = "changed_user";
updateUserRequest.userId = "test_user";
UpdateUserModel updateUserResponse = client.updateUser(updateUserRequest);
System.out.println(new Gson().toJson(updateUserResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
{
"avatar":"",
"createdAt":1572226835585,
"defaultDriveId":"",
"description":"test_user",
"domainId":"daily1405",
"email":"",
"nickName":"",
"phone":"",
"role":"user",
"status":"enabled",
"updatedAt":1572226880276,
"userId":"test_user",
"userName":"test_user"
}
// search user
public static void searchUser() throws Exception {
try {
SearchUserRequest searchUserRequest = new SearchUserRequest();
SearchUserModel listUserResponse1 = client.searchUser(searchUserRequest);
System.out.println(new Gson().toJson(listUserResponse1.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
{
"items":[
{
"avatar":"",
"createdAt":1571915575499,
"defaultDriveId":"",
"description":"",
"domainId":"daily1405",
"email":"",
"nickName":"刘***",
"phone":"",
"role":"user",
"status":"enabled",
"updatedAt":1571915575499,
"userId":"5190******************2edbf5",
"userName":"刘***"
}
],
"nextMarker":""
}
// 删除User
public static void deleteUser() throws Exception {
try {
DeleteUserRequest deleteUserRequest = new DeleteUserRequest();
deleteUserRequest.userId = "test_user";
DeleteUserModel deleteUserResponse = client.deleteUser(deleteUserRequest);
//此接口没有返回body
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
// 创建 Drive
public static void createDrive() throws Exception {
try {
CreateDriveRequest createDriveRequest = new CreateDriveRequest();
createDriveRequest.totalSize = 100000L;
createDriveRequest.driveName = "test_drive";
createDriveRequest.driveType = "normal";
createDriveRequest.owner = "superadmin";
CreateDriveModel createDriveResponse = client.createDrive(createDriveRequest);
// 打印结果
System.out.println(new Gson().toJson(createDriveResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
{
"domainId":"daily1404",
"driveId":"603"
}
// 列举 Drive
public static void listDrive() throws Exception {
try {
ListDriveRequest listDriveRequest = new ListDriveRequest();
listDriveRequest.limit = 1;
listDriveRequest.owner = "";
ListDrivesModel listDriveResponse = client.listDrives(listDriveRequest);
// 打印结果
System.out.println(new Gson().toJson(listDriveResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
{
"items":[
{
"creator":"",
"description":"",
"domainId":"daily1404",
"driveId":"603",
"driveName":"test_drive",
"driveType":"normal",
"owner":"ldh",
"relativePath":"",
"status":"enabled",
"storeId":"55ff60f575b24a8c97378f1e0a946904",
"totalSize":100000,
"usedSize":0
}
],
"nextMarker":""
}
// 查询 Drive
public static void getDrive() throws Exception {
try {
GetDriveRequest getDriveRequest = new GetDriveRequest();
getDriveRequest.driveId = "1";
GetDriveModel getDriveResponse = client.getDrive(getDriveRequest);
//打印结果
System.out.println(new Gson().toJson(getDriveResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
{
"creator":"",
"description":"",
"domainId":"daily1404",
"driveId":"603",
"driveName":"test_drive",
"driveType":"normal",
"owner":"ldh",
"relativePath":"",
"status":"enabled",
"storeId":"55ff60f575b24a8c97378f1e0a946904",
"totalSize":100000,
"usedSize":0
}
// 更新 Drive
public static void updateDrive() throws Exception {
try {
UpdateDriveRequest updateDriveRequest = new UpdateDriveRequest();
updateDriveRequest.driveId = "401";
updateDriveRequest.description = "changed_drive";
updateDriveRequest.totalSize = 1000000L;
UpdateDriveModel updateDriveResponse = client.updateDrive(updateDriveRequest);
// 打印结果
System.out.println(new Gson().toJson(updateDriveResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
{
"creator":"",
"description":"changed_drive",
"domainId":"daily1404",
"driveId":"603",
"driveName":"test_drive",
"driveType":"normal",
"owner":"ldh",
"relativePath":"",
"status":"enabled",
"storeId":"55ff60f575b24a8c97378f1e0a946904",
"totalSize":1000000,
"usedSize":0
}
// 删除 Drive
public static void deleteDrive() throws Exception {
try {
DeleteDriveRequest deleteDriveRequest = new DeleteDriveRequest();
deleteDriveRequest.driveId = "";
DeleteDriveModel deleteDriveResponse = client.deleteDrive(deleteDriveRequest);
// 此接口不返回body
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
// 创建文件
public static void createFile() throws Exception {
try {
CreateFileRequest CreateFileRequest = new CreateFileRequest();
CreateFileRequest.type = "folder";
CreateFileRequest.name = "test_folder";
CreateFileRequest.driveId = "1";
CreateFileRequest.parentFileId = "root";
CreateFileModel CreateFileResponse = client.createFile(CreateFileRequest);
// 打印结果
System.out.println(new Gson().toJson(CreateFileResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"domainId":"daily1404",
"driveId":"603",
"fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
"parentFileId":"root",
"partInfoList":[
{
"partNumber":1,
"uploadUrl":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****F943"
}
],
"rapidUpload":false,
"type":"file",
"uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943"
}
// 列举文件
public static void listFile() throws Exception {
try {
ListFileRequest ListFileRequest = new ListFileRequest();
ListFileRequest.driveId = "1";
ListFileRequest.parentFileId = "root";
ListFileRequest.limit = 1L;
ListFileModel ListFileResponse = client.listFile(ListFileRequest);
// 打印结果
System.out.println(new Gson().toJson(ListFileResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"items":[
{
"contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
"contentHashName":"sha1",
"contentType":"",
"createdAt":"2019-10-28T08:40:54.398Z",
"domainId":"daily1404",
"downloadUrl":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****.txt",
"driveId":"603",
"fileExtension":"txt",
"fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
"hidden":false,
"name":"a.txt",
"parentFileId":"5db6a996c7e9ae3a5e654a7798947b209989b963",
"size":6,
"starred":false,
"status":"available",
"type":"file",
"updatedAt":"2019-10-28T08:40:55.398Z",
"url":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****F943"
}
],
"nextMarker":""
}
// 查询File
public static void getFile() throws Exception {
try {
GetFileRequest GetFileRequest = new GetFileRequest();
GetFileRequest.driveId = "1";
GetFileRequest.fileId = "5f3b54672d4cd1b97fcb4e658385061b98d5863f";
GetFileModel GetFileResponse = client.getFile(GetFileRequest);
// 打印结果
System.out.println(new Gson().toJson(GetFileResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
"contentHashName":"sha1",
"contentType":"text/plain",
"crc64Hash":"318318745347147982",
"createdAt":"2019-10-28T08:40:54.398Z",
"domainId":"daily1404",
"downloadUrl":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****F943.txt",
"driveId":"603",
"fileExtension":"txt",
"fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
"hidden":false,
"name":"a.txt",
"parentFileId":"root",
"size":6,
"starred":false,
"status":"available",
"type":"file",
"updatedAt":"2019-10-28T08:40:55.398Z",
"uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943",
"url":"https://*********.oss-cn-hangzhou.aliyuncs.com/*****F943"
}
// 移动 File
public static void moveFile() throws Exception {
try {
MoveFileRequest MoveFileRequest = new MoveFileRequest();
MoveFileRequest.driveId = "1";
MoveFileRequest.fileId = "5f3b578fdea43919eb3d4a3bac88b614a1754f52";
MoveFileRequest.toParentFileId = "5f3b54672d4cd1b97fcb4e658385061b98d5863f";
MoveFileModel MoveFileResponse = client.moveFile(MoveFileRequest);
// 打印结果
System.out.println(new Gson().toJson(MoveFileResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"domainId":"daily1404",
"driveId":"603",
"fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f"
}
// 复制 File
public static void copyFile() throws Exception {
try {
CopyFileRequest CopyFileRequest = new CopyFileRequest();
CopyFileRequest.fileId = "5f3b578fdea43919eb3d4a3bac88b614a1754f52";
CopyFileRequest.driveId = "1";
CopyFileRequest.toParentFileId = "root";
CopyFileModel CopyFileResponse = client.copyFile(CopyFileRequest);
// 打印结果
System.out.println(new Gson().toJson(CopyFileResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"domainId":"daily1404",
"driveId":"603",
"fileId":"5db6a997ce31eb635f2e4f4c9163ec3bd10af459"
}
// 获取File上传地址
public static void getFileUploadUrl() throws Exception {
try {
UploadPartInfo uploadPartInfo = new UploadPartInfo();
uploadPartInfo.partNumber = 1L;
GetUploadUrlRequest GetUploadUrlRequest = new GetUploadUrlRequest();
GetUploadUrlRequest.driveId = "";
GetUploadUrlRequest.fileId = "";
GetUploadUrlRequest.uploadId = "";
GetUploadUrlRequest.partInfoList = new ArrayList<UploadPartInfo>();
GetUploadUrlRequest.partInfoList.add(uploadPartInfo);
GetUploadUrlModel GetUploadUrlResponse = client.getUploadUrl(GetUploadUrlRequest);
// 打印结果
System.out.println(new Gson().toJson(GetUploadUrlResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"createAt":"2019-10-28T08:40:54.519Z",
"domainId":"daily1404",
"driveId":"603",
"fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
"partInfoList":[
{
"partNumber":1,
"uploadUrl":"url":"https://****.oss-cn-hangzhou.aliyuncs.com/****wZM%3D"
}
],
"uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943"
}
// 获取File下载地址
public static void getFileDownloadUrl() throws Exception {
try {
GetDownloadUrlRequest GetDownloadUrlRequest = new GetDownloadUrlRequest();
GetDownloadUrlRequest.driveId = "1";
GetDownloadUrlRequest.fileId = "5f3f2abeb28ec23886d844e397e75fa30f5339af";
GetDownloadUrlRequest.expireSec = 3600L;
GetDownloadUrlModel GetDownloadUrlResponse = client.getDownloadUrl(GetDownloadUrlRequest);
// 打印结果
System.out.println(new Gson().toJson(GetDownloadUrlResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"expiration":"2019-10-28T09:40:55.716Z",
"method":"GET",
"url":"https://****.oss-cn-hangzhou.aliyuncs.com/****wZM%3D"
}
// 合并File分片
public static void completeFile() throws Exception {
try {
CompleteFileRequest CompleteFileRequest = new CompleteFileRequest();
UploadPartInfo uploadPartInfo = new UploadPartInfo();
CompleteFileRequest.driveId = "";
CompleteFileRequest.fileId = "";
CompleteFileRequest.uploadId = "";
CompleteFileRequest.partInfoList = new ArrayList<UploadPartInfo>(Arrays.asList(uploadPartInfo));
CompleteFileModel CompleteFileResponse = client.completeFile(CompleteFileRequest);
// 打印结果
System.out.println(new Gson().toJson(CompleteFileResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
"contentHashName":"sha1",
"contentType":"text/plain",
"crc64Hash":"318318745347147982",
"createdAt":"2019-10-28T08:40:54.398Z",
"domainId":"daily1404",
"driveId":"603",
"fileExtension":"txt",
"fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
"hidden":false,
"name":"a.txt",
"parentFileId":"root",
"size":6,
"starred":false,
"status":"available",
"type":"file",
"updatedAt":"2019-10-28T08:40:55.398Z",
"uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943",
"crc":""
}
// 更新 file
public static void updateFile() throws Exception {
try {
UpdateFileMetaRequest UpdateFileMetaRequest = new UpdateFileMetaRequest();
UpdateFileMetaRequest.fileId = "5f3b578fdea43919eb3d4a3bac88b614a1754f52";
UpdateFileMetaRequest.description = "changed_file";
UpdateFileMetaRequest.driveId = "1";
UpdateFileModel UpdateFileMetaResponse = client.updateFile(UpdateFileMetaRequest);
// 打印结果
System.out.println(new Gson().toJson(UpdateFileMetaResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
"contentHashName":"sha1",
"contentType":"text/plain",
"crc64Hash":"318318745347147982",
"createdAt":"2019-10-28T08:40:54.398Z",
"description":"changed_file",
"domainId":"daily1404",
"downloadUrl":"https://******.oss-cn-hangzhou.aliyuncs.com/5****a.txt",
"driveId":"603",
"fileExtension":"txt",
"fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
"hidden":false,
"name":"a.txt",
"parentFileId":"5db6a996c7e9ae3a5e654a7798947b209989b963",
"size":6,
"starred":false,
"status":"available",
"type":"file",
"updatedAt":"2019-10-28T08:40:55.398Z",
"uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943",
"url":"https://****.oss-cn-hangzhou.aliyuncs.com/****wZM%3D"
}
// 搜索 file
public static void searchFile() throws Exception {
try {
SearchFileRequest SearchFileRequest = new SearchFileRequest();
SearchFileRequest.driveId = "1";
SearchFileRequest.limit = 3;
SearchFileRequest.orderBy = "type DESC";
SearchFileRequest.query = "file_extension in [\"txt\"]";
SearchFileModel SearchFileResponse = client.searchFile(SearchFileRequest);
// 打印结果
System.out.println(new Gson().toJson(SearchFileResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
{
"items":[
{
"contentHash":"7C4A8D09CA3762AF61E59520943DC26494F8941B",
"contentHashName":"sha1",
"contentType":"text/plain",
"crc64Hash":"318318745347147982",
"createdAt":"2019-10-28T08:40:54.398Z",
"description":"changed_file",
"domainId":"daily1404",
"downloadUrl":"https://************.oss-cn-hangzhou.aliyuncs.com/***a.txt",
"driveId":"603",
"fileExtension":"txt",
"fileId":"5db6a996aa1292d7563644f0bc4847107171ed7f",
"hidden":false,
"name":"a.txt",
"parentFileId":"5db6a996c7e9ae3a5e654a7798947b209989b963",
"size":6,
"starred":false,
"status":"available",
"type":"file",
"updatedAt":"2019-10-28T08:40:55.398Z",
"uploadId":"DEB65A38FCCA410BAC6DD23A8A11F943",
"url":"https://****.oss-cn-hangzhou.aliyuncs.com/****ZM%3D"
}
],
"nextMarker":""
}
// 删除 file
public static void deleteFile() throws Exception {
try {
DeleteFileRequest DeleteFileRequest = new DeleteFileRequest();
DeleteFileRequest.driveId = "1";
DeleteFileRequest.fileId = "5f3b578fdea43919eb3d4a3bac88b614a1754f52";
DeleteFileModel deleteFileResponse = client.deleteFile(DeleteFileRequest);
System.out.println(new Gson().toJson(deleteFileResponse.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
public static void batch() throws Exception {
try {
BatchRequest BatchRequest = new BatchRequest();
BatchRequest.resource = "file";
BatchSubRequest batchSubRequest = new BatchSubRequest();
Map<String, Object> bodyMap = new HashMap<String, Object>();
bodyMap.put("drive_id", "1");
bodyMap.put("file_id", "5f3b578fdea43919eb3d4a3bac88b614a1754f52");
batchSubRequest.body = bodyMap;
batchSubRequest.url = "/file/get";
batchSubRequest.method = "POST";
batchSubRequest.id = "uuid";
BatchRequest.requests = new ArrayList<BatchSubRequest>(Arrays.asList(batchSubRequest));
BatchOperationModel response = client.batchOperation(BatchRequest);
System.out.println(new Gson().toJson(response.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
}
}
{
"responses":[
{
"status":200,
"body":{
"file_extension":"txt",
"updated_at":"2020-03-30T08:15:58.267Z",
"content_hash":"FAA12FD40AAC1F492082C90C2CD6C03B9ABDB826",
"domain_id":"hz22",
"size":36,
"category":"doc",
"content_hash_name":"sha1",
"download_url":"https://ccp-daily-default-c**n-han***Z8bG%2B9C4VII%3D",
"crc64_hash":"13138712399852734283",
"drive_id":"1",
"hidden":false,
"type":"file",
"parent_file_id":"root",
"status":"available",
"description":"changed_file",
"encrypt_mode":"none",
"file_id":"5e81aabdae****d9836b36",
"content_type":"application/oct-stream",
"name":"testDJw8oWE6ef9464f66e5034f69aafd57cb2879170b.txt",
"url":"https://ccp-daily-default-c**n-han***Z8bG%2B9C4VII%3D",
"created_at":"2020-03-30T08:15:57.361Z",
"upload_id":"DFD1DA39317F45EC8534FEA57AE420D1",
"starred":false
},
"id":"624830fa2c2347be8c0d8afc76faa04d"
}
]
}
public void listUploadedPart() throws Exception {
try {
ListUploadedPartRequest ListUploadedPartRequest = new ListUploadedPartRequest();
ListUploadedPartRequest.driveId = "1";
ListUploadedPartRequest.fileId = "****";
ListUploadedPartRequest.uploadId = "****";
ListUploadedPartsModel response = client.listUploadedParts(ListUploadedPartRequest);
System.out.println(new Gson().toJson(response.body));
} catch (TeaException e) {
System.out.println(e.getMessage());
}
}
{
"drive_id" : "1",
"file_id" : "5d5b846942cf94fa72324c14a4bda34e81da635d",
"limit" : 1,
"part_number_marker" : 1,
"upload_id" : "00668396C0814D818D90F0A92B04B355"
}
public void getAsyncTask() throws Exception {
try {
GetAsyncTaskRequest getAsyncTaskRequest = new GetAsyncTaskRequest();
getAsyncTaskRequest.asyncTaskId = "***";
GetAsyncTaskInfoModel response = client.getAsyncTaskInfo(getAsyncTaskRequest);
System.out.println(new Gson().toJson(response.headers));
} catch (TeaException e) {
System.out.println(e.getMessage());
}
}
{
"async_task_id" : "000e89fb-cf8f-11e9-8ab4-b6e980803a3b",
"message" : "task is running",
"state" : "success"
}
import com.aliyun.pds.client.Client;
import com.aliyun.pds.client.models.*;
import com.aliyun.tea.TeaException;
import com.google.gson.Gson;
import okhttp3.*;
import java.util.*;
public class Demo {
private static Client client;
private static RuntimeOptions runtime;
public static void main(String[] args) throws Exception{
createClient();
createFile();
}
public static void createClient() throws Exception {
Config config = new Config();
config.domainId= "your domain id";
config.protocol = "https";
config.accessKeyId = "your accessKeyId";
config.accessKeySecret = "your accessKeySecret";
client = new Client(config);
runtime = new RuntimeOptions();
}
public static void createFullFile() throws Exception{
try{
System.out.println("-------------create file----------------");
CreateFileRequest CreateFileRequest = new CreateFileRequest();
CreateFileRequest.type = "file";
CreateFileRequest.name = "a.txt";
CreateFileRequest.driveId = "1";
CreateFileRequest.parentFileId = "root";
CreateFileRequest.contentType = "text/plain";
CreateFileModel CreateFileResponse = client.createFile(CreateFileRequest);
System.out.println(new Gson().toJson(CreateFileResponse.body));
String uploadId = CreateFileResponse.body.uploadId;
String fileId = CreateFileResponse.body.fileId;
String uploadUrl = CreateFileResponse.body.partInfoList.get(0).uploadUrl;
// upload file
System.out.println("-------------upload file----------------");
Request.Builder requestBuilder = new Request.Builder();
RequestBody body = RequestBody.create(MediaType.parse(""), "123456");
requestBuilder.url(uploadUrl);
requestBuilder.put(body);
Request request = requestBuilder.build();
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
Response response = okHttpClient.newCall(request).execute();
String etag = response.headers().get("ETag");
System.out.println();
// complete file
System.out.println("-------------complete file----------------");
UploadPartInfo uploadPartInfo1 = new UploadPartInfo();
uploadPartInfo1.etag = etag;
uploadPartInfo1.partNumber = 1L;
CompleteFileRequest CompleteFileRequest = new CompleteFileRequest();
CompleteFileRequest.driveId = "1";
CompleteFileRequest.fileId = fileId;
CompleteFileRequest.uploadId = uploadId;
CompleteFileRequest.partInfoList = new ArrayList<UploadPartInfo>(Arrays.asList(uploadPartInfo1));
CompleteFileModel CompleteFileResponse = client.completeFile(CompleteFileRequest);
System.out.println(new Gson().toJson(CompleteFileResponse.body));
}catch (TeaException e) {
System.out.println(e.getMessage());
System.out.println(e.getCode());
System.out.println(new Gson().toJson(e.getData()));
}
}
}
本文介绍云监控中SAE的监控项。 当您调用云监控的API接口时,需要获取当前云产品...
前提条件 在执行本章操作前,请确认您注册华为云帐号并完成实名认证。 国际站 用...
场景说明 如果您的网站 “www.example.com” 除了需要账号密码登录,还有其他的...
调用OpenSlsService接口开通日志服务。只有开通服务后,才能进行日志服务的操作...
操作场景 API 网关组件是 serverless-tencent 组件库中的基础组件之一,您可以通...
这个文章主题在我自己的看板里面躺了很久了 其实并不是不想写 而是一直没有勇气...
本文介绍在配置E-MapReduce完成后,如何卸载并释放E-MapReduce HDFS服务使用的云...
TOP云 (west.cn)10月12日讯,海外消息,近日威瑞信发布了9月份 域名注册 热门...
您可以在创建云桌面时直接分配用户,也可以在云桌面创建完成后重新分配用户。本...
本文包含了五个知识点: 数据挖掘与机器学习技术简介 Python数据预处理实战 常见...