gpt4 book ai didi

java - 从 GCP 存储桶读取文件的 NoSuchMethod

转载 作者:行者123 更新时间:2023-12-02 09:30:46 24 4
gpt4 key购买 nike

我正在尝试使用此代码从 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,它会崩溃。

关于java - 从 GCP 存储桶读取文件的 NoSuchMethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58009110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com