\Think\Upload\Driver\BcsBaiduBCS

BCS API

Summary

Methods
Properties
Constants
__construct()
list_bucket()
create_bucket()
delete_bucket()
set_bucket_acl()
get_bucket_acl()
list_object()
list_object_by_dir()
create_object()
create_object_by_content()
create_object_superfile()
upload_directory()
copy_object()
set_object_meta()
get_object_acl()
set_object_acl()
delete_object()
is_object_exist()
get_object_info()
get_object()
generate_get_object_url()
generate_put_object_url()
generate_post_object_url()
generate_delete_object_url()
generate_head_object_url()
getUse_ssl()
setUse_ssl()
validate_bucket()
validate_object()
trimUrl()
get_filetree()
log()
$ACL_ACTIONS
$ACL_EFFECTS
$ACL_TYPES
DEFAULT_URL
API_VERSION
ACL
BUCKET
OBJECT
HEADERS
METHOD
AK
SK
QUERY_STRING
IMPORT_BCS_LOG_METHOD
IMPORT_BCS_PRE_FILTER
IMPORT_BCS_POST_FILTER
STATEMETS
BCS_SDK_ACL_ACTION_ALL
BCS_SDK_ACL_ACTION_LIST_OBJECT
BCS_SDK_ACL_ACTION_PUT_BUCKET_POLICY
BCS_SDK_ACL_ACTION_GET_BUCKET_POLICY
BCS_SDK_ACL_ACTION_DELETE_BUCKET
BCS_SDK_ACL_ACTION_GET_OBJECT
BCS_SDK_ACL_ACTION_PUT_OBJECT
BCS_SDK_ACL_ACTION_DELETE_OBJECT
BCS_SDK_ACL_ACTION_PUT_OBJECT_POLICY
BCS_SDK_ACL_ACTION_GET_OBJECT_POLICY
BCS_SDK_ACL_EFFECT_ALLOW
BCS_SDK_ACL_EFFECT_DENY
BCS_SDK_ACL_TYPE_PUBLIC_READ
BCS_SDK_ACL_TYPE_PUBLIC_WRITE
BCS_SDK_ACL_TYPE_PUBLIC_READ_WRITE
BCS_SDK_ACL_TYPE_PUBLIC_CONTROL
BCS_SDK_ACL_TYPE_PRIVATE
No protected methods found
$use_ssl
N/A
authenticate()
generate_user_url()
set_header_into_opt()
array_recursive()
array_to_json()
analyze_user_acl()
format_signature()
check_user_acl()
format_url()
assertParameterArray()
$ak
$sk
$hostname
N/A

Constants

DEFAULT_URL

DEFAULT_URL = 'bcs.duapp.com'

API_VERSION

API_VERSION = '2012-4-17-1.0.1.6'

ACL

ACL = 'acl'

BUCKET

BUCKET = 'bucket'

OBJECT

OBJECT = 'object'

HEADERS

HEADERS = 'headers'

METHOD

METHOD = 'method'

AK

AK = 'ak'

SK

SK = 'sk'

QUERY_STRING

QUERY_STRING = "query_string"

IMPORT_BCS_LOG_METHOD

IMPORT_BCS_LOG_METHOD = "import_bs_log_method"

IMPORT_BCS_PRE_FILTER

IMPORT_BCS_PRE_FILTER = "import_bs_pre_filter"

IMPORT_BCS_POST_FILTER

IMPORT_BCS_POST_FILTER = "import_bs_post_filter"

STATEMETS

STATEMETS = 'statements'

BCS_SDK_ACL_ACTION_ALL

BCS_SDK_ACL_ACTION_ALL = '*'

BCS_SDK_ACL_ACTION_LIST_OBJECT

BCS_SDK_ACL_ACTION_LIST_OBJECT = 'list_object'

BCS_SDK_ACL_ACTION_PUT_BUCKET_POLICY

BCS_SDK_ACL_ACTION_PUT_BUCKET_POLICY = 'put_bucket_policy'

BCS_SDK_ACL_ACTION_GET_BUCKET_POLICY

BCS_SDK_ACL_ACTION_GET_BUCKET_POLICY = 'get_bucket_policy'

BCS_SDK_ACL_ACTION_DELETE_BUCKET

BCS_SDK_ACL_ACTION_DELETE_BUCKET = 'delete_bucket'

BCS_SDK_ACL_ACTION_GET_OBJECT

BCS_SDK_ACL_ACTION_GET_OBJECT = 'get_object'

BCS_SDK_ACL_ACTION_PUT_OBJECT

BCS_SDK_ACL_ACTION_PUT_OBJECT = 'put_object'

BCS_SDK_ACL_ACTION_DELETE_OBJECT

BCS_SDK_ACL_ACTION_DELETE_OBJECT = 'delete_object'

BCS_SDK_ACL_ACTION_PUT_OBJECT_POLICY

BCS_SDK_ACL_ACTION_PUT_OBJECT_POLICY = 'put_object_policy'

BCS_SDK_ACL_ACTION_GET_OBJECT_POLICY

BCS_SDK_ACL_ACTION_GET_OBJECT_POLICY = 'get_object_policy'

BCS_SDK_ACL_EFFECT_ALLOW

BCS_SDK_ACL_EFFECT_ALLOW = "allow"

BCS_SDK_ACL_EFFECT_DENY

BCS_SDK_ACL_EFFECT_DENY = "deny"

BCS_SDK_ACL_TYPE_PUBLIC_READ

BCS_SDK_ACL_TYPE_PUBLIC_READ = "public-read"

BCS_SDK_ACL_TYPE_PUBLIC_WRITE

BCS_SDK_ACL_TYPE_PUBLIC_WRITE = "public-write"

BCS_SDK_ACL_TYPE_PUBLIC_READ_WRITE

BCS_SDK_ACL_TYPE_PUBLIC_READ_WRITE = "public-read-write"

BCS_SDK_ACL_TYPE_PUBLIC_CONTROL

BCS_SDK_ACL_TYPE_PUBLIC_CONTROL = "public-control"

BCS_SDK_ACL_TYPE_PRIVATE

BCS_SDK_ACL_TYPE_PRIVATE = "private"

Properties

$ACL_ACTIONS

$ACL_ACTIONS : 

Type

$ACL_EFFECTS

$ACL_EFFECTS : 

Type

$ACL_TYPES

$ACL_TYPES : 

Type

$use_ssl

$use_ssl : 

Type

$ak

$ak : 

Type

$sk

$sk : 

Type

$hostname

$hostname : 

Type

Methods

__construct()

__construct(string  $ak = NULL, string  $sk = NULL, string  $hostname = NULL) 

构造函数

Parameters

string $ak

云存储公钥

string $sk

云存储私钥

string $hostname

云存储Api访问地址

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

list_bucket()

list_bucket(array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

获取当前密钥对拥有者的bucket列表

Parameters

array $opt

(Optional) BaiduBCS::IMPORT_BCS_LOG_METHOD - String - Optional: 支持用户传入日志处理函数,函数定义如 function f($log)

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

create_bucket()

create_bucket(string  $bucket, string  $acl = NULL, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

创建 bucket

Parameters

string $bucket

(Required) bucket名称

string $acl

(Optional) bucket权限设置,若为null,使用server分配的默认权限

array $opt

(Optional)

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

delete_bucket()

delete_bucket(string  $bucket, array  $opt = array()) : boolean|\Think\Upload\Driver\Bcs\BCS_ResponseCore

删除bucket

Parameters

string $bucket

(Required)

array $opt

(Optional)

Returns

boolean|\Think\Upload\Driver\Bcs\BCS_ResponseCore

set_bucket_acl()

set_bucket_acl(string  $bucket, string  $acl, array  $opt = array()) : boolean|\Think\Upload\Driver\Bcs\BCS_ResponseCore

设置bucket的acl,有三种模式, (1).设置详细json格式的acl; a. $acl 为json的array b. $acl 为json的string (2).通过acl_type字段进行设置 a. $acl 为BaiduBCS::$ACL_TYPES中的字段

Parameters

string $bucket

(Required)

string $acl

(Required)

array $opt

(Optional)

Returns

boolean|\Think\Upload\Driver\Bcs\BCS_ResponseCore

get_bucket_acl()

get_bucket_acl(string  $bucket, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

获取bucket的acl

Parameters

string $bucket

(Required)

array $opt

(Optional)

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

list_object()

list_object(string  $bucket, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

获取bucket中object列表

Parameters

string $bucket

(Required)

array $opt

(Optional) start : 主要用于翻页功能,用法同mysql中start的用法 limit : 主要用于翻页功能,用法同mysql中limit的用法 prefix: 只返回以prefix为前缀的object,此处prefix必须以'/'开头

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

list_object_by_dir()

list_object_by_dir(string  $bucket,   $dir = '/', string  $list_model = 2, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

以目录形式获取bucket中object列表

Parameters

string $bucket

(Required)

$dir

(Required) 目录名,格式为必须以'/'开头和结尾,默认为'/'

string $list_model

(Required) 目录展现形式,值可以为0,1,2,默认为2,以下对各个值的功能进行介绍: 0->只返回object列表,不返回子目录列表 1->只返回子目录列表,不返回object列表 2->同时返回子目录列表和object列表

array $opt

(Optional) start : 主要用于翻页功能,用法同mysql中start的用法 limit : 主要用于翻页功能,用法同mysql中limit的用法

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

create_object()

create_object(string  $bucket, string  $object, string  $file, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

上传文件

Parameters

string $bucket

(Required)

string $object

(Required)

string $file

(Required); 需要上传的文件的文件路径

array $opt

(Optional) filename - Optional; 指定文件名 acl - Optional ; 上传文件的acl,只能使用acl_type seekTo - Optional; 上传文件的偏移位置 length - Optional; 待上传长度

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

create_object_by_content()

create_object_by_content(string  $bucket, string  $object,   $content, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

上传文件

Parameters

string $bucket

(Required)

string $object

(Required)

$content
array $opt

(Optional) filename - Optional; 指定文件名 acl - Optional ; 上传文件的acl,只能使用acl_type

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

create_object_superfile()

create_object_superfile(string  $bucket, string  $object, string  $file, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

通过superfile的方式上传文件

Parameters

string $bucket

(Required)

string $object

(Required)

string $file

(Required); 需要上传的文件的文件路径

array $opt

(Optional) filename - Optional; 指定文件名 sub_object_size - Optional; 指定子文件的划分大小,单位B,建议以256KB为单位进行子object划分,默认为1MB进行划分

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

upload_directory()

upload_directory(string  $bucket, string  $dir,   $opt = array()) : array

将目录中的所有文件进行上传,每个文件为单独object,object命名方式下详: 如有 /home/worker/a/b/c.txt 需上传目录为$dir=/home/worker/a object命令方式为 1. object默认命名方式为 “子目录名 +文件名”,如上述文件c.txt,默认为 '/b/c.txt' 2. 增强命名模式,在$opt中有可选参数进行配置 举例说明 :prefix . has_sub_directory?"/b":"" . '/c.txt'

Parameters

string $bucket

(Required)

string $dir

(Required)

$opt

Returns

array —

数组形式的上传结果 'success' => int 上传成功的文件数目 'skipped' => int 被跳过的文件 'failed' => array() 上传失败的文件

copy_object()

copy_object(array  $source, array  $dest, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

通过此方法以拷贝的方式创建object,object来源为$source

Parameters

array $source

(Required) object 来源 bucket(Required) object(Required)

array $dest

(Required) 待拷贝的目标object bucket(Required) object(Required)

array $opt

(Optional) source_tag 指定拷贝对象的版本号

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

set_object_meta()

set_object_meta(string  $bucket, string  $object,   $meta, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

设置object的meta信息

Parameters

string $bucket

(Required)

string $object

(Required)

$meta
array $opt

(Optional) 目前支持的meta信息如下: Content-Type Cache-Control Content-Disposition Content-Encoding Content-MD5 Expires

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

get_object_acl()

get_object_acl(string  $bucket, string  $object, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

获取object的acl

Parameters

string $bucket

(Required)

string $object

(Required)

array $opt

(Optional)

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

set_object_acl()

set_object_acl(string  $bucket, string  $object, string|array  $acl, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

设置object的acl,有三种模式, (1).设置详细json格式的acl; a. $acl 为json的array b. $acl 为json的string (2).通过acl_type字段进行设置 a. $acl 为BaiduBCS::$ACL_ACTIONS中的字段

Parameters

string $bucket

(Required)

string $object

(Required)

string|array $acl

(Required)

array $opt

(Optional)

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

delete_object()

delete_object(string  $bucket, string  $object, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

删除object

Parameters

string $bucket

(Required)

string $object

(Required)

array $opt

(Optional)

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

is_object_exist()

is_object_exist(string  $bucket, string  $object, array  $opt = array()) : boolean

判断object是否存在

Parameters

string $bucket

(Required)

string $object

(Required)

array $opt

(Optional)

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

boolean —

true|boolean false|BCS_ResponseCore true:object存在 false:不存在 BCS_ResponseCore其他错误

get_object_info()

get_object_info(string  $bucket, string  $object, array  $opt = array()) : array

获取文件信息,发送的为HTTP HEAD请求,文件信息都在http response的header中,不会提取文件的内容

Parameters

string $bucket

(Required)

string $object

(Required)

array $opt

(Optional)

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

array —

BCS_ResponseCore

get_object()

get_object(string  $bucket, string  $object, array  $opt = array()) : \Think\Upload\Driver\Bcs\BCS_ResponseCore

下载object

Parameters

string $bucket

(Required)

string $object

(Required)

array $opt

(Optional) fileWriteTo (Optional)直接将请求结果写入该文件,如果fileWriteTo文件存在,sdk进行重命名再存储

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

\Think\Upload\Driver\Bcs\BCS_ResponseCore

generate_get_object_url()

generate_get_object_url(string  $bucket, string  $object,   $opt = array()) 

生成get_object的url

Parameters

string $bucket

(Required)

string $object

(Required) return false| string url

$opt

generate_put_object_url()

generate_put_object_url(string  $bucket, string  $object,   $opt = array()) 

生成put_object的url

Parameters

string $bucket

(Required)

string $object

(Required) return false| string url

$opt

generate_post_object_url()

generate_post_object_url(string  $bucket, string  $object,   $opt = array()) 

生成post_object的url

Parameters

string $bucket

(Required)

string $object

(Required) return false| string url

$opt

generate_delete_object_url()

generate_delete_object_url(string  $bucket, string  $object,   $opt = array()) 

生成delete_object的url

Parameters

string $bucket

(Required)

string $object

(Required) return false| string url

$opt

generate_head_object_url()

generate_head_object_url(string  $bucket, string  $object,   $opt = array()) 

生成head_object的url

Parameters

string $bucket

(Required)

string $object

(Required) return false| string url

$opt

getUse_ssl()

getUse_ssl() : \Think\Upload\Driver\Bcs\the

Returns

\Think\Upload\Driver\Bcs\the —

$use_ssl

setUse_ssl()

setUse_ssl(boolean  $use_ssl) 

Parameters

boolean $use_ssl

validate_bucket()

validate_bucket(string  $bucket) : boolean

校验bucket是否合法,bucket规范 1. 由小写字母,数字和横线'-'组成,长度为6~63位 2. 不能以数字作为Bucket开头 3. 不能以'-'作为Bucket的开头或者结尾

Parameters

string $bucket

Returns

boolean

validate_object()

validate_object(string  $object) : boolean

校验object是否合法,object命名规范 1. object必须以'/'开头

Parameters

string $object

Returns

boolean

trimUrl()

trimUrl(  $url) : string

将url中 '//' 替换为 '/'

Parameters

$url

Returns

string

get_filetree()

get_filetree(string  $dir,   $file_prefix = "/*") : array

获取传入目录的文件列表

Parameters

string $dir

文件目录

$file_prefix

Returns

array —

文件树

log()

log(string  $log, array  $opt) 

内置的日志函数,可以根据用户传入的log函数,进行日志输出

Parameters

string $log
array $opt

generate_user_url()

generate_user_url(  $method,   $bucket,   $object,   $opt = array()) 

生成签名链接

Parameters

$method
$bucket
$object
$opt

set_header_into_opt()

set_header_into_opt(string  $header, string  $value, array  $opt) : void

将常用set http-header的动作抽离出来

Parameters

string $header
string $value
array $opt

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

array_recursive()

array_recursive(  $array, string  $function, boolean  $apply_to_keys_also = false) 

使用特定function对数组中所有元素做处理

Parameters

$array
string $function

要执行的函数

boolean $apply_to_keys_also

是否也应用到key上

array_to_json()

array_to_json(array  $array) 

由数组构造json字符串,增加了一些特殊处理以支持特殊字符和不同编码的中文

Parameters

array $array

analyze_user_acl()

analyze_user_acl(string|array  $acl) : array

根据用户传入的acl,进行相应的处理 (1).设置详细json格式的acl; a. $acl 为json的array b. $acl 为json的string (2).通过acl_type字段进行设置

Parameters

string|array $acl

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

array

format_signature()

format_signature(array  $opt) : boolean|string

生成签名

Parameters

array $opt

Returns

boolean|string

check_user_acl()

check_user_acl(array  $acl) : string

检查用户输入的acl array是否合法,并转为json

Parameters

array $acl

Throws

\Think\Upload\Driver\Bcs\BCS_Exception

Returns

string —

acl-json

format_url()

format_url(array  $opt) : boolean|string

构造url

Parameters

array $opt

Returns

boolean|string

assertParameterArray()

assertParameterArray(  $opt) 

make sure $opt is an array

Parameters

$opt