一時的Web公開(Temporary URL)
Description
一時的にオブジェクトを公開する場合に使用します。 Temp-Url-Keyを登録後に下記方法等にてURLを作成する必要があります。
・URL作成スクリプトを作成する
・Swift-temp-urlクライアントを使用する
Request URL
ObjectStorage API v1 POST /v1/ze_{account}
Request Json
This operation does not accept a request body.
Request Parameters
Parameter | Value | Style | Description |
---|---|---|---|
X-Auth-Token | Userトークン | header | トークン発行 にて払い出されたID |
account | テナントID | URI | API情報を確認する にてご確認ください。 |
container | コンテナ名 | URI | アカウント情報・コンテナ一覧取得にてご確認ください。 |
X-Account-Meta-Temp-URL-Key(Optional) | string | header | tempurl用のKey |
X-Remove-Account-Meta-Temp-URL-Key(Optional) | string | header |
Response
-
Normal response codes
204
Example
-
Request
curl -i -X POST \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "X-Auth-Token: トークンID" \ -H 'X-Account-Meta-Temp-URL-Key: tempurl用のKey' \ https://object-storage.jpt1.cloud.z.com/v1/ze_テナントID
-
Response
HTTP/1.1 204 No Content Content-Length: 0 Content-Type: text/html; charset=UTF-8 X-Trans-Id: txb384cc23284e479cb4fb4-0057bc1694 Date: Tue, 23 Aug 2016 09:25:40 GMT
Using
1.コンテナを作成しオブジェクトをアップロード
2.tempurl用のKeyを登録
curl -i -X POST \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "X-Auth-Token: トークンID" \ -H 'X-Account-Meta-Temp-URL-Key: tempurl用のKey' \ https://object-storage.jpt1.cloud.z.com/v1/ze_テナントID
3.tempurl生成するため、下記モジュールを作成
※ここでは24時間で生成、またモジュール名はcreate-tempurl.pyとします。
# vim create-tempurl.py 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/ze_テナントID/コンテナ名/オブジェクト名' key = 'tempurl用のKey' 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='object-storage.jpt1.cloud.z.com', path=path, sig=sig, expires=expires) print '%s' % url
4.モジュールを実行
/usr/bin/python create-tempurl.py