如何在JAVA中从google存储云存储桶获取所有pdf文件
在bucket文件夹中,我可以从google存储中获取pdf文件。我如何从那里下载一个文件中的所有文件。 为了一个文件如何在JAVA中从google存储云存储桶获取所有pdf文件,java,google-cloud-platform,google-cloud-functions,google-cloud-storage,Java,Google Cloud Platform,Google Cloud Functions,Google Cloud Storage,在bucket文件夹中,我可以从google存储中获取pdf文件。我如何从那里下载一个文件中的所有文件。 为了一个文件 public InputStream getBlobBytesArray() { String bucketName ="XYZ"; String filename="abc.pdf"; Blob blob = getStorageInstance().get(BlobId.of(bucketName, filen
public InputStream getBlobBytesArray() {
String bucketName ="XYZ";
String filename="abc.pdf";
Blob blob = getStorageInstance().get(BlobId.of(bucketName, filename));
return new ByteArrayInputStream(getStorageInstance().readAllBytes(blob.getBlobId()));
}
在这个桶里,我创建了一个文件夹,其中存储了5个pdf文件。
怎么把它们都拿来
public MultipartFile getMultiFileFromCloud() {
// TODO Auto-generated method stub
String bucketName = "XYZ";
Blob fileBlob = getStorageInstance().get(BlobId.of(bucketName, filepath));
MultipartFile multipartFile = new CommonsMultipartFile( new ByteArrayInputStream(fileBlob.getContent(BlobSourceOption.generationMatch())));
return null;
}
我已经尝试过了,但没有效果。提前谢谢。您只能通过文件全名的前缀(包括路径)来搜索文件。如果要查找后缀或内容类型元数据,则需要获取所有文件并用代码选择所需内容(例如名称中的*.pdf扩展名)
然后,您不能通过一个命令下载它们,只能逐个下载。谷歌存储提供了查找文件夹中所有对象的方法
public InputStream getBlobBytesArray() {
String bucketName ="XYZ";
Bucket bucket = storage.get(bucketName);
Page<Blob>blobs=bucket.list(Storage.BlobListOption.prefix("folderPath/1"));
}
public InputStream getBlobBytesArray(){
字符串bucketName=“XYZ”;
Bucket=storage.get(bucketName);
Pageblobs=bucket.list(Storage.BlobListOption.prefix(“folderPath/1”);
}
现在这对我来说很好