簡體   English   中英

Box API Java:如何將文件移到另一個文件夾?

[英]Box API Java: How can I move a file into another folder?

所以我試圖將文件移到另一個文件夾。 Box API表示以下內容

要移動文件夾,請更新其父文件夾的ID。

但是在BoxItem.Info上似乎沒有用於setID()的方法,就像有setName()一樣

我正在嘗試做類似於此處的api示例的操作

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)的文件提供一個新名稱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");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM