簡體   English   中英

NoSuchMethod 從 GCP 存儲桶中讀取文件

[英]NoSuchMethod on reading file from a GCP Bucket

我正在嘗試使用此代碼從 Google Cloud Storage 存儲桶中讀取文件

Blob blob = storage.get(BlobId.of(Constants.GCS_BUCKET, srcFilename));
printBlob(blob.reader());
private void printBlob(ReadChannel reader) {
    try {
        WritableByteChannel outChannel = Channels.newChannel(System.out);
        ByteBuffer bytes = ByteBuffer.allocate(64 * 1024);
        while (reader. read(bytes) > 0) {
            bytes.flip();
            outChannel.write(bytes);
            bytes.clear();
        }
    }
    catch (Exception e) {

    }

}

執行reader.read(bytes)時,代碼會拋出此異常

[INFO] GCLOUD: Caused by: 
[INFO] GCLOUD: java.lang.NoSuchMethodError: com.google.api.services.storage.Storage$Objects$Get.setReturnRawInputStream(Z)Lcom/google/api/client/googleapis/services/AbstractGoogleClientRequest;
[INFO] GCLOUD:  at com.google.cloud.storage.spi.v1.HttpStorageRpc.createReadRequest(HttpStorageRpc.java:658)
[INFO] GCLOUD:  at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:693)
[INFO] GCLOUD:  at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:127)
[INFO] GCLOUD:  at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:124)

解決了。 需要使用依賴

    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-core-http</artifactId>
        <version>1.91.0</version>
    </dependency>

如果您使用 1.90.0,它會崩潰。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM