[英]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对象,在下面的代码中我试图获取该文件的先前版本,但我无法获得特定版本的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
}
所以我测试了你的代码而没有删除以前的版本,它似乎工作。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.