【发布时间】:2019-09-20 19:21:38
【问题描述】:
我正在尝试使用此代码从 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)
【问题讨论】:
-
下载文件时也会出现 -> blob.downloadTo(Paths.get("/tmp/"+srcFilename));
-
你在学习任何教程吗?
标签: java google-cloud-platform