2017-05-05 8 views
1

私は以下のコードを使用してファイルの最新バージョンを入手できますか? Box-SDKを使用してバージョン番号とファイルIDを使用して以前のバージョンのBoxFileVersionオブジェクトを取得する方法は?

BoxFile file = new BoxFile(api,fileId); 
BoxFile.Info info = file.getInfo("version_number","file_version"); 
info.getVersionNumber(); // current version No. 

は今、私は特定のバージョン番号についてBoxFileVersionオブジェクトをフェッチしたかった、以下のコードでは、私は、以前のバージョンのファイルを取得しようとしましたが、私は、特定のバージョンの バージョン番号を取得することができません

Collection<BoxFileVersion> versions = file.getVersions(); // Fetching the Previous Version of the Files 
    if(versions.size() != 0){  // If there is no Previous Versions 
     for(BoxFileVersion bfv : versions){ 
       if(bfv.getTrashedAt() == null){ 
        bfv.promote(); 
        boxFileVersion.delete(); 
        System.out.println("Deleted Version ID : "+boxFileVersion.getVersionID()); 
        break; 
       } 
      } 
    } 
    else{ 
      file.delete(); // delete the file if no previous version exist 
     } 

答えて

0

以前のバージョンを削除せずにコードをテストしたところ、うまくいきました。

BoxFile file = new BoxFile(userApi, "xxxxxx"); 
     System.out.println("file current version: " + file.getInfo().getVersion().getVersionID()); 

     Collection<BoxFileVersion> versions = file.getVersions(); // Fetching the Previous Version of the Files 

     int versionIndex = versions.size(); 
     if (versions.size() != 0) {  // If there is no Previous Versions 
      for (BoxFileVersion bfv : versions) { 
       if (versionIndex == versions.size()) // the first one is the previous version 
       { 
        bfv.promote(); 
        bfv.delete(); 
        System.out.println("Deleted Version ID : "+ bfv.getVersionID()); 
       } 
       System.out.println("bfv: [" + versionIndex-- + "] " + bfv.getVersionID() + " " + bfv.getCreatedAt()); 
      } 
     } 

バージョン番号ではないようですが、バージョンIDはありません。だから私は、バージョン#はバージョン配列内の位置にすぎないと思います。

file current version: xxxx42182218 
Deleted Version ID : xxxx42064367 
bfv: [4] xxxx42064367 Tue May 09 16:43:54 PDT 2017 
bfv: [3] xxxx32054815 Tue May 09 16:28:50 PDT 2017 
bfv: [2] xxxx28578550 Tue May 09 16:19:47 PDT 2017 
bfv: [1] xxxx28578201 Tue May 09 16:19:41 PDT 2017 
file current version: xxxx47266430 
+0

私はそれを削除することができたバージョンIDを使用して:

、ここでは出力です。 – arunkumarmsk

関連する問題