I have a list of files in a Google Bucket. I have to create a folder in Google Drive and upload all files into that folder from the Google Bucket. I am uploading the files correctly, but I am not able to upload the files into a specific folder. One by one the files are uploaded in the Drive root folder, but I want them in a particular folder.
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();
}
}