我在将文件上传到谷歌驱动器中的现有文件夹时遇到问题。它一直告诉我“xxx”不存在。

String folderId = "Storage";

ChildReference newChild = new ChildReference();
newChild.setId(fileContent.getName());

drive.children().insert(folderId, newChild).execute();

来自 https://developers.google.com/drive/v2/reference/children/insert

最佳答案

是的,最后我可以将我的整个文件目录上传到谷歌驱动器中的特定文件夹,因为文件夹 ID 不匹配。

我使用 setParents 函数在以下代码中取得了成功。

String folderId = "0BwI6rRcqw8ZURlpleEVsRUhod0U";

File fileContent = new java.io.File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/" + Files[count].getName());

FileContent mediaContent = new FileContent("image/jpeg", fileContent);

com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File();

body.setTitle(fileContent.getName());
body.setMimeType("image/jpeg");

body.setParents(Arrays.asList(new ParentReference().setId(folderId)));

com.google.api.services.drive.model.File file = drive.files().insert(body, mediaContent).execute();

关于google-drive-api - 将文件上传到 Google Drive 中的指定文件夹,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13903106/

10-16 11:06