【发布时间】:2021-03-02 14:24:07
【问题描述】:
我有一个 Google 存储桶中的文件列表。我必须在 Google Drive 中创建一个文件夹并将所有文件从 Google Bucket 上传到该文件夹中。我正在正确上传文件,但无法将文件上传到特定文件夹。文件一一上传到云端硬盘根文件夹中,但我希望它们在特定文件夹中。
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();
}
}
【问题讨论】:
标签: java google-drive-api google-cloud-storage google-cloud-datastore