View Source AlibabaCloudKit.OSS (alibaba_cloud_kit v0.7.0)
A kit for OSS style API.
Read more at:
- Object Storage Service > Developer Reference > Developer Guide > Use the RESTful API to initiate requests
- 对象存储 > 开发参考 > 开发指南 > 使用 REST API 发起请求
The base URL
Following formats can be used:
- region URL, such as
https://oss-us-west-1.aliyuncs.com
. - virtual-hosted style URL, such as
https://example-bucket.oss-us-west-1.aliyuncs.com
. - custom domain name, such as
https://www.example.com
. - ...
Adding signature
This implementation has built-in OSS4 signature support, and it's controlled
by the :sign_type
option:
:header
- add signature to the headers of a request.:query
- add signature to the query of a request.
V1 signature is not supported.
Required headers
All necessary headers of requests will be generated automatically. You don't have to specifically set them, unless you want to customize it.
Examples
Build and sign a request for ListBucktets
operation
request = HTTPSpec.Request.new!(
method: :get,
scheme: :https,
host: "oss-us-west-1.aliyuncs.com",
port: 443,
path: "/"
)
opts = [
access_key_id: "...",
access_key_secret: "...",
region: "oss-us-west-1",
sign_type: :header
]
AlibabaCloudKit.OSS.sign_request!(request, opts)
Build a pre-signed url for GetObject
operation
request = HTTPSpec.Request.new!(
method: :get,
scheme: :https,
host: "example-bucket.oss-us-west-1.aliyuncs.com",
port: 443,
path: "/example-object",
headers: [
{"x-oss-expires", "900"}
]
)
opts = [
access_key_id: "...",
access_key_secret: "...",
region: "oss-us-west-1",
bucket: "example-bucket",
sign_type: :query
]
request
|> AlibabaCloudKit.OSS.sign_request!(opts)
|> HTTPSpec.Request.build_url()
Summary
Functions
Signs a request with OSS4 signature.
Types
@type access_key_id() :: String.t()
@type access_key_secret() :: String.t()
@type at() :: DateTime.t() | nil
@type bucket() :: String.t() | nil
@type region() :: String.t()
@type sign_opt() :: {:access_key_id, access_key_id()} | {:access_key_secret, access_key_secret()} | {:region, region()} | {:bucket, bucket()} | {:sign_type, sign_type()} | {:at, at()}
@type sign_opts() :: [sign_opt()]
@type sign_type() :: :header | :query
Functions
@spec sign_request!(HTTPSpec.Request.t(), sign_opts()) :: HTTPSpec.Request.t()
Signs a request with OSS4 signature.