gpt4 book ai didi

java - 使用 BlobStore 为对象生成临时 URI

转载 作者:行者123 更新时间:2023-12-02 05:47:58 25 4
gpt4 key购买 nike

我正在尝试使用 jClouds BlobStore 功能为 OpenStack Swift 容器中存储的对象实现临时 GET URI 的生成。

但是我收到这些错误:

java.lang.IllegalStateException: Suppliers.memoizeWithExpiration(get().getTemporaryUrlKey() using {annotationParser={caller=SwiftApi.accountApiInRegion[RegionOne]}}, 60000000000, NANOS) returned a null temporaryUrlKey!
at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
at org.jclouds.openstack.swift.v1.TemporaryUrlSigner.hmacSHA1(TemporaryUrlSigner.java:63)
at org.jclouds.openstack.swift.v1.TemporaryUrlSigner.sign(TemporaryUrlSigner.java:57)
at org.jclouds.openstack.swift.v1.blobstore.RegionScopedTemporaryUrlBlobSigner.sign(RegionScopedTemporaryUrlBlobSigner.java:100)
at org.jclouds.openstack.swift.v1.blobstore.RegionScopedTemporaryUrlBlobSigner.signGetBlob(RegionScopedTemporaryUrlBlobSigner.java:73)

这是一个代码示例:

public class BlobStoreObjectSignerService implements ObjectSignerService {

@Autowired
private BlobRequestSigner blobRequestSigner;

@Value("${blobStore.private.container}")
String privateContainerName;

/**
* Generates signed request With GET Method to access allocated object.
*
* @param objectName name of the stored file
* @param principalName name of the principal (user) which is putted the file
* @param temporary defines if file should be available for a limited time
* @param timeToLive time in seconds file will be available for fetching
*/
public HttpRequest generateGetRequestForObject( String objectName,
String principalName,
boolean temporary,
long timeToLive ) {
if (temporary) {
return this.generateTemporaryGetRequestForObject(objectName, principalName, timeToLive);
} else {
return this.generatePermanentGetRequestForObject(objectName, principalName);
}
}

public HttpRequest generatePermanentGetRequestForObject( String objectName,
String principalName ) {
return this.generatePermanentGetRequestForObject( privateContainerName,
String.format( "/%s/%s", principalName, objectName ) );
}

public HttpRequest generateTemporaryGetRequestForObject( String objectName,
String principalName,
long timeToLive ) {
return this.generateTemporaryGetRequestForObject( privateContainerName,
String.format( "/%s/%s", principalName, objectName ),
timeToLive );
}

public HttpRequest generatePermanentGetRequestForObject(String containerName, String objectName) {
return this.blobRequestSigner.signGetBlob(containerName, objectName);
}

public HttpRequest generateTemporaryGetRequestForObject(String containerName, String objectName, long timeToLive) {
return this.blobRequestSigner.signGetBlob(containerName, objectName, timeToLive);
}

}

对于公共(public)容器,我仍然可以通过获取 header /元数据来获取对象链接,这有点侧面,但我仍然需要签名的 URI 来发布存储在私有(private)容器中的对象。

使用 BlobStore 将文件放入容器效果很好。所有推送通常都由 OpenStack Dashboard 显示。

我仅在开发环境中使用为 Swift 配置的 Java 7 和 DevStack。jClouds版本是1.7.2。

最佳答案

根据异常情况,您似乎没有在帐户上设置临时 URL key 。您可以通过 AccountApi 将 key 更新为新值,如下所示:

SwiftApi swiftApi = ContextBuilder.newBuilder(PROVIDER)
.credentials("{username}", "{apiKey}")
.buildApi(SwiftApi.class);

// Access the accountApi
AccountApi accountApi = swiftApi.getAccountApiForRegion("{regionId");
accountApi.updateTemporaryUrlKey("{newKey}");

// Access the key
String tempUrlKey;
if (accountApi.getTemporaryUrlKey().isPresent()) {
tempUrlKey = accountApi.get().getTemporaryUrlKey().get();
}

希望有帮助!

关于java - 使用 BlobStore 为对象生成临时 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23861948/

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