【问题标题】:Box API Java: How can I move a file into another folder?Box API Java:如何将文件移动到另一个文件夹中?
【发布时间】:2019-01-23 15:39:47
【问题描述】:

所以我试图将文件移动到另一个文件夹中。 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() 文件方法,它存在于文件夹中。

【问题讨论】:

标签: java box-api box


【解决方案1】:

不要使用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");

【讨论】:

  • 这正是我想要的,谢谢!希望这反映在 API 文档中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-08
  • 1970-01-01
  • 2010-09-08
  • 2010-09-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多