All Products
Document Center

Overview and preparation

Last Updated: Aug 30, 2021


MDS provides Java SDK for offline package release, enabling developers to configure, create, release, and manage offline packages by calling the API.


Before using the open API, you need to obtain AccessKey, App ID, Workspace ID and Tenant ID, configure Maven dependencies and configure file uploading.

Obtain AccessKey

AccessKey includes AccessKey ID and AccessKey Secret. Click here for obtaining method.

  • AccessKey ID: used to identify users.
  • AccessKey Secret: used for user authentication. MUST be kept safe.

Obtain App ID, Workspace ID and Tenant ID

  1. Log in to mPaaS console, and enter the App.
  2. In Overview page, click Code configurations (choose Android or iOS based on your needs)> Download configuration file > Download now. You can view App ID and Workspace ID in the Code configurations panel.

Configure Maven dependencies

Before using the API, you need to complete the following Maven dependency configurations.

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-mpaas</artifactId>
  4. <version>3.0.5</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.aliyun</groupId>
  8. <artifactId>aliyun-java-sdk-core</artifactId>
  9. <optional>true</optional>
  10. <version>[4.3.2,5.0.0)</version>
  11. </dependency>

Code sample

The following shows the code sample of using Client in Maven:

  1. private static final String REGION_ID = "cn-hangzhou"; //Region ID, the default is cn-hangzhou
  2. private static final String ACCESS_KEY_ID = "*****************"; //AccessKey ID of RAM account
  3. private static final String ACCESS_SECRET = "******************"; //AccessKey Secret of RAM account
  4. private static final String PRODUCT = "mpaas"; //Product name
  5. private static final String END_POINT = ""; //The endpoint that is called
  6. DefaultProfile.addEndpoint(REGION_ID, PRODUCT, END_POINT);
  7. DefaultProfile profile = DefaultProfile.getProfile(REGION_ID, ACCESS_KEY_ID, ACCESS_SECRET);
  8. IAcsClient iAcsClient = new DefaultAcsClient(profile);
  9. QueryMcubeVhostRequest queryMcubeVhostRequest = new QueryMcubeVhostRequest();
  10. queryMcubeVhostRequest.setAppId(APP_ID);
  11. queryMcubeVhostRequest.setWorkspaceId(WORKSPACE_ID);
  12. queryMcubeVhostRequest.setTenantId(TENANT_ID);
  13. QueryMcubeVhostResponse acsResponse = null;
  14. try {
  15. acsResponse = iAcsClient.getAcsResponse(queryMcubeVhostRequest);
  16. System.out.println(acsResponse.getResultCode());
  17. System.out.println(acsResponse.getQueryVhostResult());
  18. } catch (ClientException e) {
  19. e.printStackTrace();
  20. }

Configure file uploading

Since file streaming is not allowed in all APIs, to upload a file, you need to upload it to OSS first by calling the upload tool class, and then send the returned OSS address as a parameter to the specified API.

You can download the file upload tool class

Code sample

The following shows the code sample of file uploading:

  1. GetMcubeFileTokenRequest getMcubeFileTokenRequest = new GetMcubeFileTokenRequest();
  2. getMcubeFileTokenRequest.setAppId(APP_ID);
  3. getMcubeFileTokenRequest.setOnexFlag(true);
  4. getMcubeFileTokenRequest.setTenantId(TENANT_ID);
  5. getMcubeFileTokenRequest.setWorkspaceId(WORKSPACE_ID);
  6. GetMcubeFileTokenResponse acsResponse = iAcsClient.getAcsResponse(getMcubeFileTokenRequest);
  7. System.out.println(JSON.toJSONString(acsResponse));
  8. GetMcubeFileTokenResponse.GetFileTokenResult.FileToken fileToken = acsResponse.getGetFileTokenResult().getFileToken();
  9. OssPostObject ossPostObject = new OssPostObject();
  10. ossPostObject.setKey(fileToken.getDir());
  11. ossPostObject.setHost(fileToken.getHost());
  12. ossPostObject.setOssAccessId(fileToken.getAccessid());
  13. ossPostObject.setPolicy(fileToken.getPolicy());
  14. ossPostObject.setSignature(fileToken.getSignature());
  15. ossPostObject.setFilePath("your/local/file/path");
  16. String s = ossPostObject.postObject();

Refer to Obtain upload file token for descriptions about GetMcubeFileTokenRequest.