如何使用REST API为Swift对象存储创建临时URL? [英] How to create temporary URL for Swift object storage using REST API?

查看:275
本文介绍了如何使用REST API为Swift对象存储创建临时URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速对象存储使您可以为具有到期日期的任何资源创建一个临时URL.这可以通过快速的CLI命令行来实现.为了在Web应用程序中使用此功能,我需要使用API​​调用来实现临时URL的创建,以便我可以进行其余的CALL并获取临时URL,该URL以后可以嵌入HTML并由我们下载资源直接浏览器.

Swift Object storage allow you to create a temporary URL for any resource with an expiry date. This can be achieved with swift CLI command line. To make use of this functionality in an web application, I need to achieve the creation of temporary URL using API call, So that I can make a rest CALL and get the temp URL which can later be embedded in HTML and resource downloaded by the we browser directly.

从文档中我看不到为此提到的任何API吗?有谁知道我如何使用API​​调用从Java中获取它.

From the documentation I dont see any API mentioned for this ? Do anyone know how i can get it from Java using API call.

谢谢 马诺伊

推荐答案

没有直接的API可用于为Swift对象生成临时URL.取而代之的是,必须根据

There is no direct API available to generate temporary URL for Swift objects. Instead it has to generated from client side with the help of X-Account-Meta-Temp-URL-Key secret key as per described in this document

这是生成它的python版本的代码.引用它可以在Java中重新实现它,然后可以将其嵌入任何地方.

Here is the python version of code to generate it. Refer this to re-implement it in Java and then it can be embedded anywhere.

import hmac
from hashlib import sha1
from time import time
method = 'GET'
duration_in_seconds = 60*60*24
expires = int(time() + duration_in_seconds)
path = '/v1/AUTH_a422b2-91f3-2f46-74b7-d7c9e8958f5d30/container/object'
key = 'mykey'
hmac_body = '%s\n%s\n%s' % (method, expires, path)
sig = hmac.new(key, hmac_body, sha1).hexdigest()
s = 'https://{host}/{path}?temp_url_sig={sig}&temp_url_expires={expires}'
url = s.format(host='swift-cluster.example.com', path=path, sig=sig, expires=expires)

这是另一个参考,它是对Openstack Horizo​​n提供UI功能,以生成快速对象的临时URL.

Here is an another reference, which is a customization done to Openstack Horizon to provide an UI feature to generate swift objects temp URL.

这篇关于如何使用REST API为Swift对象存储创建临时URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆