qiniu v0.3.5 Qiniu.PutPolicy

PutPolicy struct for uploading. And you have to specify right scope and deadline to let uploading work.

See http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html

Summary

Functions

A better way to build PutPolicy, which can calculate deadline for you from expires_in(seconds) and can accpet the options. See build/2, build/3

Change put_policy to json string and encode it with url safe

Change put_policy to json string expect the nil values, whose keys are camelCase

Types

t :: %Qiniu.PutPolicy{callback_body: String.t | nil, callback_body_type: String.t | nil, callback_fetch_key: integer | nil, callback_host: String.t | nil, callback_url: String.t | nil, checksum: String.t | nil, deadline: integer, detect_mime: integer | nil, end_user: String.t | nil, fsize_limit: integer | nil, insert_only: integer | nil, mime_limit: String.t | nil, persistent_notify_url: String.t | nil, persistent_ops: String.t | nil, persistent_pipeline: String.t | nil, return_body: String.t | nil, return_url: String.t | nil, save_key: String.t | nil, scope: String.t}

Functions

build(scope)

Specs

build(String.t) :: t

A better way to build PutPolicy, which can calculate deadline for you from expires_in(seconds) and can accpet the options. See build/2, build/3.

Examples

iex> Qiniu.PutPolicy.build("scope")
%Qiniu.PutPolicy{scope: "scope", deadline: NOW_TIME + 3600}
build(scope, expires_in_or_options)

Specs

build(String.t, Integer.t | Keyword.t) :: t

build/2

Examples

iex> Qiniu.PutPolicy.build("scope", 4000)
%Qiniu.PutPolicy{scope: "scope", deadline: NOW_TIME + 4000}

iex> Qiniu.PutPolicy.build("scope", insert_only: 1)
%Qiniu.PutPolicy{scope: "scope", deadline: NOW_TIME + 3600, insert_only: 1}
build(scope, expires_in, opts)

Specs

build/3

Examples

iex> Qiniu.PutPolicy.build("scope", 4000, insert_only: 1)
%Qiniu.PutPolicy{scope: "scope", deadline: NOW_TIME + 4000, insert_only: 1}

# scope and deadline in options won't be used for override
iex> Qiniu.PutPolicy.build("scope", 4000, scope: "other_scope")
%Qiniu.PutPolicy{scope: "scope", deadline: NOW_TIME + 4000}
encoded_json(policy)

Specs

encoded_json(Qiniu.PutPolicy.t) :: String.t

Change put_policy to json string and encode it with url safe

Examples

iex> policy = %Qiniu.PutPolicy{scope: "scope"}
iex> Qiniu.PutPolicy.encoded_json(policy)
"eyJzY29wZSI6InNjb3BlIn0="
to_json(policy)

Specs

Change put_policy to json string expect the nil values, whose keys are camelCase.

Examples

iex> policy = %Qiniu.PutPolicy{scope: "scope", deadline: 1427990400, return_body: "body"}
iex> Qiniu.PutPolicy.to_json(policy)
~s({"scope":"scope","returnBody":"body","deadline":1427990400})