gpt4 book ai didi

java - 无法在 JOSS-openstack 中生成带有过期时间的临时 GET url

转载 作者:太空宇宙 更新时间:2023-11-04 11:16:21 25 4
gpt4 key购买 nike

我正在尝试从我的 openstack swift 容器之一生成临时 URL。但是当我访问该网址时,它给我 401 Unauthorized: Temp URL invalid

这是我的做法的示例版本。

package com.raja.openstack;

import org.javaswift.joss.client.factory.AccountConfig;
import org.javaswift.joss.client.factory.AccountFactory;
import org.javaswift.joss.client.factory.AuthenticationMethod;
import org.javaswift.joss.model.Account;
import org.javaswift.joss.model.Container;
import org.javaswift.joss.model.StoredObject;

import java.io.File;
import java.util.Map;

/**
* Created by raja on 04-05-2017.
*/
public class OpenStackSwiftTest {
public static void main(String[] args) {
//create config
AccountConfig config = new AccountConfig();
config.setAuthUrl("myhosting.url/auth/v1.0/");
config.setAuthenticationMethod(AuthenticationMethod.BASIC);
config.setUsername("admin");
config.setPassword("PasswordDuh");
config.setHashPassword("blah"); //The API documentation insists this

//create account from config
Account account = new AccountFactory(config).createAccount();

Map<String, Object> metadata1 = account.getMetadata();
metadata1.forEach((s, o) -> {
System.out.println(s+":"+o);
});

Container container = account.getContainer("mycontainer");


//open a stored object handle
StoredObject storedObject = container.getObject("TEST.txt");

//upload something
storedObject.uploadObject("Hello World!!".getBytes());

//get the temporary URL.
String tempGetUrl = storedObject.getTempGetUrl(1000);

System.out.println(tempGetUrl);

}
}

上面的代码打印如下内容

Quota-Bytes:107374182400
Temp-Url-Key:blah
myhosting.url/v1/AUTH_admin/mycontainer/TEST.txt?temp_url_sig=5e38222a1b74fe1ae874a946ccb6f4cce043dcdb&temp_url_expires=1501517432

当我尝试访问该 URL 时,收到 401 Unauthorized: Temp URL invalid

但是,当我运行以下命令时,可以直接在浏览器上访问生成的 URL 并下载内容。

swift tempurl GET 60 myhosting.url/v1/AUTH_admin/mycontainer/TEST.txt blah -U admin -K PasswordDuh

这是我执行stat时的服务器配置

                          StorageURL: myhosting.url/v1/AUTH_admin
Auth Token: AUTH_tkbd65506826b12317a7a3e03e0f547c78
Account: AUTH_admin
Containers: 10
Objects: 147553
Bytes: 26544582500
Containers in policy "del-resilient": 1
Objects in policy "del-resilient": 571
Bytes in policy "del-resilient": 12312
Meta Quota-Bytes: 4182400
Meta Temp-Url-Key: blah
X-Openstack-Request-Id: tx69915eb0be0f43e89333e-00597f525c
Accept-Ranges: bytes
Connection: Keep-alive
Via: 1.1 ID-0314217254230750 uproxy-3
X-Timestamp: 1493105849.12206
X-Trans-Id: tx69915eb03456u3e89222e-00597f525c
Content-Type: text/plain; charset=utf-8

我的 Java 代码中缺少什么?下面是joss依赖

   <dependency>
<groupId>org.javaswift</groupId>
<artifactId>joss</artifactId>
<version>0.9.15</version>
</dependency>

最佳答案

这是一个错误。解决方案在这里:https://github.com/javaswift/joss/pull/90/commits/105f70c8d4a3409b5de3504ba3eb07444f8b607c

这是一个拉取请求,但尚未获得批准。

关于java - 无法在 JOSS-openstack 中生成带有过期时间的临时 GET url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45420710/

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