我可以使用下面的代码获取该文件的当前版本吗?
BoxFile file = new BoxFile(api,fileId);
BoxFile.Info info = file.getInfo("version_number","file_version");
info.getVersionNumber(); // current version No.
现在我想获取给定版本号的BoxFileVersion对象,在下面的代码中我试图获取该文件的先前版本,但我无法获得特定的 VERSION NUMBER 版本
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 :(得分: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。所以我想版本#&#39; s只是版本数组中的位置。
以及输出:
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