Box API Java:如何将文件移到另一个文件夹?

时间:2018-08-16 15:57:40

标签: java box-api box

因此,我试图将文件移到另一个文件夹。 盒子api表示以下内容

  

要移动文件夹,请更新其父文件夹的ID。

但是在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()的文件方法,它存在于文件夹中。

1 个答案:

答案 0 :(得分:0)

要使用目标文件夹移动文件,请使用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");