[英]How to create folder dynamic and upload multiples file using Java Google Drive API
我有一個 Google 存儲桶中的文件列表。 我必須在 Google Drive 中創建一個文件夾並將所有文件從 Google Bucket 上傳到該文件夾中。 我正在正確上傳文件,但無法將文件上傳到特定文件夾。 文件一一上傳到 Drive 根文件夾中,但我希望它們在特定文件夾中。
Page<Blob> blobs = bucket.list(Storage.BlobListOption.prefix(BucketUrl));
Drive driveService = DriveConfUtil.getDriveService(accessToken);
for (Blob fileBlob: blobs.getValues()) {
InputStream inputStream = new
ByteArrayInputStream(fileBlob.getContent(BlobSourceOption.generationMatch()));
File file = new File();
file.setName(fileBlob.getName());
file.setMimeType("application/mydocfolder.folder");
File file1 = null;
try {
AbstractInputStreamContent streamContent = null;
streamContent = new InputStreamContent("application/pdf", inputStream);
file1 = driveService.files().create(file, streamContent).setFields("id").execute();
} catch (IOException e) {
e.printStackTrace();
}
}
我知道您的腳本正確上傳了文件,但它是在 Drive 主文件夾而不是您想要的文件夾中這樣做的。 您只需在請求正文中填寫parents[]
參數即可輕松解決此問題。 要在該參數中指定文件夾,您需要它的 ID。 請記住,雲端硬盤文件可以同時托管在不同的文件夾中。 不要猶豫,問我任何澄清。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.