简体   繁体   中英

How to get all pdf file from google storage cloud bucket in JAVA

In a bucket folder I can get pdf file from google storage. how can i download all files in ones from there. Eg.for a single file.

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()));

}

Inside the bucket I have create one folder where 5 pdf are store. How to fetch them all'

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;
    }

I have tried this nothing working.thanks in advance.

Google storage provide the way to find out all objects inside the folder.

public InputStream getBlobBytesArray() {
    String bucketName ="XYZ";
Bucket bucket = storage.get(bucketName);

Page<Blob>blobs=bucket.list(Storage.BlobListOption.prefix("folderPath/1"));  
}

Now this is working fine for me.

You can search file only by prefix of their full name (path included). If you look for a suffix, or a content type metadata, you need to fetch all the files and select with your code what you want (the *.pdf extension in the name for example).

Then you can't download them in one command, but only one by one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM