所以我试图将文件移动到另一个文件夹中。 Box api 的内容如下
To move a folder, update the ID of its parent.
但是 BoxItem.Info 上似乎没有 setID() 的方法,就像 setName() 一样
我正在尝试执行类似于 api 示例 here 的操作
BoxFile file = new BoxFile(api, fileID);
BoxFile.Info info = file.new Info();
String parentID = info.getParent().getID();
BoxFolder parentFolder = new BoxFolder(api, parentID);
BoxFolder.Info parentInfo = parentFolder.new Info();
parentInfo.setID(newID); // Method doesn't exist
parentFolder.updateInfo(parentInfo);
对我来说也很奇怪的是,没有一个简单的 .move() 文件方法,它存在于文件夹中。
最佳答案
不要使用 updateInfo
方法,而是对要与目标文件夹一起移动的文件使用 move(BoxFolder destination)
。
代码示例:
String fileID = "1234";
String destinationFolderID = "5678";
BoxFile file = new BoxFile(api, fileID);
BoxFolder destinationFolder = new BoxFolder(destinationFolderID);
file.move(destinationFolder)
此外,为了避免目标文件夹中的名称冲突,您可以选择为要 move(BoxFolder destination, String newName)
的文件提供一个新名称。该文件将以新名称放置到目标文件夹中。
代码示例:
String fileID = "1234";
String destinationFolderID = "5678";
BoxFile file = new BoxFile(api, fileID);
BoxFolder destinationFolder = new BoxFolder(destinationFolderID);
file.move(destinationFolder, "Vacation Photo (1).jpg");
关于java - 盒子 API Java : How can I move a file into another folder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51881094/