Box-SDK如何通过版本号和fileID获取上一版本的BoxFileVersion对象?

How to get the BoxFileVersion object of the previous version by using the version number and fileID using Box-SDK?

我可以使用下面的代码获取文件的当前版本吗?

 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
      }

所以我在不删除以前版本的情况下测试了你的代码,它似乎可以工作。

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