📜  Cloudrail-Java

📅  最后修改于: 2020-10-30 14:11:45             🧑  作者: Mango


本节介绍如何使用CloudRail的Java SDK。

建立

最简单的安装方法是通过Maven。只需将以下内容添加到您的pom.xml文件中-


   
      com.cloudrail
      cloudrail-si-java
      2.8.0
   

用法

以下示例显示如何创建新文件夹并将文件从本地计算机上载到任何云存储提供商上的新创建的文件夹。

java
CloudRail.setAppKey("[CloudRail License Key]");

// CloudStorage cs = new Box(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// CloudStorage cs = new OneDrive(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// CloudStorage cs = new GoogleDrive(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
CloudStorage cs = new Dropbox(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
new Thread() {
   @Override
   public void run() {
      cs.createFolder("/TestFolder");
      InputStream stream = null;
      
      try {
         stream = getClass().getResourceAsStream("Data.csv");
         long size = new File(getClass().getResource("Data.csv").toURI()).length();
         cs.upload("/TestFolder/Data.csv", stream, size, false);
      } catch (Exception e) {
         // TODO: handle error
      } finally {
         // TODO: close stream
      }
   }
}.start();