gpt4 book ai didi

java - 无法从 Google Cloud Storage 返回对象名称

转载 作者:行者123 更新时间:2023-12-02 01:34:22 24 4
gpt4 key购买 nike

我按照以下格式在 Google Cloud 中存储对象

bucketname/UUID/object

例如,我在 Google 云中有一个对象,存储为

roshanbucket/1fa0e7b4-b551-4e5c-a491-8d86f06a1eef/test.txt

这是我用来返回对象名称的方法

public String getFileName(String bucketName, String uuid) {
final String[] fileName = {null};
Page<Blob> blobs = storage.list(bucketName, BlobListOption.prefix(uuid));
blobs.iterateAll().forEach(
blob -> fileName[0] = blob.getName()//.substring(blob.getName().lastIndexOf('/') + 1)
);
return fileName[0];
}

这是测试方法

@Test
public void testGetFileName(){
String fileName = googleCloudStorage.getFileName("roshanbucket", "1fa0e7b4-b551-4e5c-a491-8d86f06a1eef");
System.out.println(fileName);
}

当我运行测试时,出现以下错误

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V

at com.google.cloud.storage.StorageImpl.optionMap(StorageImpl.java:1279)
at com.google.cloud.storage.StorageImpl.optionMap(StorageImpl.java:1268)
at com.google.cloud.storage.StorageImpl.optionMap(StorageImpl.java:1301)
at com.google.cloud.storage.StorageImpl.list(StorageImpl.java:306)
at services.fileserver.GoogleCloudStorage.getFileName(GoogleCloudStorage.java:76)
at services.fileserver.GoogleCloudStorageTest.testDownloadLink(GoogleCloudStorageTest.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

如何解决这个问题?

最佳答案

谷歌提供的你的jar版本似乎是错误的。检查包含 Precondition.class 的 jar 文件的版本

关于java - 无法从 Google Cloud Storage 返回对象名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55451060/

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