我正在尝试从我的一个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
当我尝试访问该网址时,我收到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>
答案 0 :(得分:0)
这是一个错误。 解决方案如下:https://github.com/javaswift/joss/pull/90/commits/105f70c8d4a3409b5de3504ba3eb07444f8b607c
这是拉取请求,但尚未批准。