我将对象存储为以下格式的
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)
如何解决此问题?
答案 0 :(得分:1)
Google提供的jar版本似乎不正确。 检出包含Precondition.class
的jar文件的版本答案 1 :(得分:1)
添加此依赖性可解决此问题
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
答案 2 :(得分:0)
我建议按照documentation中的步骤操作,以获取正确的Java客户端库。当前在此处指定的pom.xml依赖项如下
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<label>Privileges:</label>
<select name="privileges" id="privileges">
<option id="all" value="all">All</option>
<option id="custom" value="custom">Custom</option>
</select>
</div>
<div class="resources" style=" display: none;">resources</div>