\OSSOssClient

Class OssClient

Object Storage Service(OSS) 的客户端类,封装了用户通过OSS API对OSS服务的各种操作, 用户通过OssClient实例可以进行Bucket,Object,MultipartUpload, ACL等操作,具体 的接口规则可以参考官方OSS API文档

Summary

Methods
Properties
Constants
__construct()
listBuckets()
createBucket()
deleteBucket()
doesBucketExist()
getBucketAcl()
putBucketAcl()
getObjectAcl()
putObjectAcl()
getBucketLogging()
putBucketLogging()
deleteBucketLogging()
putBucketWebsite()
getBucketWebsite()
deleteBucketWebsite()
putBucketCors()
getBucketCors()
deleteBucketCors()
addBucketCname()
getBucketCname()
deleteBucketCname()
putBucketLiveChannel()
putLiveChannelStatus()
getLiveChannelInfo()
getLiveChannelStatus()
getLiveChannelHistory()
listBucketLiveChannels()
postVodPlaylist()
deleteBucketLiveChannel()
signRtmpUrl()
optionsObject()
putBucketLifecycle()
getBucketLifecycle()
deleteBucketLifecycle()
putBucketReferer()
getBucketReferer()
listObjects()
createObjectDir()
putObject()
uploadFile()
appendObject()
appendFile()
copyObject()
getObjectMeta()
deleteObject()
deleteObjects()
getObject()
doesObjectExist()
generateMultiuploadParts()
initiateMultipartUpload()
uploadPart()
listParts()
abortMultipartUpload()
completeMultipartUpload()
listMultipartUploads()
uploadPartCopy()
multiuploadFile()
uploadDir()
signUrl()
setMaxTries()
getMaxRetries()
setSignStsInUrl()
isUseSSL()
setUseSSL()
checkEnv()
setTimeout()
setConnectTimeout()
$OSS_ACL_TYPES
OSS_LIFECYCLE_EXPIRATION
OSS_LIFECYCLE_TIMING_DAYS
OSS_LIFECYCLE_TIMING_DATE
OSS_BUCKET
OSS_OBJECT
OSS_HEADERS
OSS_METHOD
OSS_QUERY
OSS_BASENAME
OSS_MAX_KEYS
OSS_UPLOAD_ID
OSS_PART_NUM
OSS_COMP
OSS_LIVE_CHANNEL_STATUS
OSS_LIVE_CHANNEL_START_TIME
OSS_LIVE_CHANNEL_END_TIME
OSS_POSITION
OSS_MAX_KEYS_VALUE
OSS_MAX_OBJECT_GROUP_VALUE
OSS_MAX_PART_SIZE
OSS_MID_PART_SIZE
OSS_MIN_PART_SIZE
OSS_FILE_SLICE_SIZE
OSS_PREFIX
OSS_DELIMITER
OSS_MARKER
OSS_ACCEPT_ENCODING
OSS_CONTENT_MD5
OSS_SELF_CONTENT_MD5
OSS_CONTENT_TYPE
OSS_CONTENT_LENGTH
OSS_IF_MODIFIED_SINCE
OSS_IF_UNMODIFIED_SINCE
OSS_IF_MATCH
OSS_IF_NONE_MATCH
OSS_CACHE_CONTROL
OSS_EXPIRES
OSS_PREAUTH
OSS_CONTENT_COING
OSS_CONTENT_DISPOSTION
OSS_RANGE
OSS_ETAG
OSS_LAST_MODIFIED
OS_CONTENT_RANGE
OSS_CONTENT
OSS_BODY
OSS_LENGTH
OSS_HOST
OSS_DATE
OSS_AUTHORIZATION
OSS_FILE_DOWNLOAD
OSS_FILE_UPLOAD
OSS_PART_SIZE
OSS_SEEK_TO
OSS_SIZE
OSS_QUERY_STRING
OSS_SUB_RESOURCE
OSS_DEFAULT_PREFIX
OSS_CHECK_MD5
DEFAULT_CONTENT_TYPE
OSS_URL_ACCESS_KEY_ID
OSS_URL_EXPIRES
OSS_URL_SIGNATURE
OSS_HTTP_GET
OSS_HTTP_PUT
OSS_HTTP_HEAD
OSS_HTTP_POST
OSS_HTTP_DELETE
OSS_HTTP_OPTIONS
OSS_ACL
OSS_OBJECT_ACL
OSS_OBJECT_GROUP
OSS_MULTI_PART
OSS_MULTI_DELETE
OSS_OBJECT_COPY_SOURCE
OSS_OBJECT_COPY_SOURCE_RANGE
OSS_PROCESS
OSS_CALLBACK
OSS_CALLBACK_VAR
OSS_SECURITY_TOKEN
OSS_ACL_TYPE_PRIVATE
OSS_ACL_TYPE_PUBLIC_READ
OSS_ACL_TYPE_PUBLIC_READ_WRITE
OSS_ENCODING_TYPE
OSS_ENCODING_TYPE_URL
OSS_HOST_TYPE_NORMAL
OSS_HOST_TYPE_IP
OSS_HOST_TYPE_SPECIAL
OSS_HOST_TYPE_CNAME
OSS_NAME
OSS_VERSION
OSS_BUILD
OSS_AUTHOR
OSS_OPTIONS_ORIGIN
OSS_OPTIONS_REQUEST_METHOD
OSS_OPTIONS_REQUEST_HEADERS
No protected methods found
No protected properties found
N/A
computePartSize()
precheckOptions()
precheckBucket()
precheckObject()
precheckCommon()
precheckParam()
isCheckMD5()
getValue()
getMimeType()
auth()
authPrecheckBucket()
authPrecheckObject()
authPrecheckObjectEncoding()
authPrecheckAcl()
generateHostname()
generateResourceUri()
generateSignableQueryStringParam()
generateSignableResource()
generateQueryString()
stringToSignSorted()
generateHeaders()
generateUserAgent()
checkEndpoint()
$useSSL
$maxRetries
$redirects
$hostType
$requestUrl
$accessKeyId
$accessKeySecret
$hostname
$securityToken
$enableStsInUrl
$timeout
$connectTimeout
N/A

Constants

OSS_LIFECYCLE_EXPIRATION

OSS_LIFECYCLE_EXPIRATION

OSS_LIFECYCLE_TIMING_DAYS

OSS_LIFECYCLE_TIMING_DAYS

OSS_LIFECYCLE_TIMING_DATE

OSS_LIFECYCLE_TIMING_DATE

OSS_BUCKET

OSS_BUCKET

OSS_OBJECT

OSS_OBJECT

OSS_HEADERS

OSS_HEADERS

OSS_METHOD

OSS_METHOD

OSS_QUERY

OSS_QUERY

OSS_BASENAME

OSS_BASENAME

OSS_MAX_KEYS

OSS_MAX_KEYS

OSS_UPLOAD_ID

OSS_UPLOAD_ID

OSS_PART_NUM

OSS_PART_NUM

OSS_COMP

OSS_COMP

OSS_LIVE_CHANNEL_STATUS

OSS_LIVE_CHANNEL_STATUS

OSS_LIVE_CHANNEL_START_TIME

OSS_LIVE_CHANNEL_START_TIME

OSS_LIVE_CHANNEL_END_TIME

OSS_LIVE_CHANNEL_END_TIME

OSS_POSITION

OSS_POSITION

OSS_MAX_KEYS_VALUE

OSS_MAX_KEYS_VALUE

OSS_MAX_OBJECT_GROUP_VALUE

OSS_MAX_OBJECT_GROUP_VALUE

OSS_MAX_PART_SIZE

OSS_MAX_PART_SIZE

OSS_MID_PART_SIZE

OSS_MID_PART_SIZE

OSS_MIN_PART_SIZE

OSS_MIN_PART_SIZE

OSS_FILE_SLICE_SIZE

OSS_FILE_SLICE_SIZE

OSS_PREFIX

OSS_PREFIX

OSS_DELIMITER

OSS_DELIMITER

OSS_MARKER

OSS_MARKER

OSS_ACCEPT_ENCODING

OSS_ACCEPT_ENCODING

OSS_CONTENT_MD5

OSS_CONTENT_MD5

OSS_SELF_CONTENT_MD5

OSS_SELF_CONTENT_MD5

OSS_CONTENT_TYPE

OSS_CONTENT_TYPE

OSS_CONTENT_LENGTH

OSS_CONTENT_LENGTH

OSS_IF_MODIFIED_SINCE

OSS_IF_MODIFIED_SINCE

OSS_IF_UNMODIFIED_SINCE

OSS_IF_UNMODIFIED_SINCE

OSS_IF_MATCH

OSS_IF_MATCH

OSS_IF_NONE_MATCH

OSS_IF_NONE_MATCH

OSS_CACHE_CONTROL

OSS_CACHE_CONTROL

OSS_EXPIRES

OSS_EXPIRES

OSS_PREAUTH

OSS_PREAUTH

OSS_CONTENT_COING

OSS_CONTENT_COING

OSS_CONTENT_DISPOSTION

OSS_CONTENT_DISPOSTION

OSS_RANGE

OSS_RANGE

OSS_ETAG

OSS_ETAG

OSS_LAST_MODIFIED

OSS_LAST_MODIFIED

OS_CONTENT_RANGE

OS_CONTENT_RANGE

OSS_CONTENT

OSS_CONTENT

OSS_BODY

OSS_BODY

OSS_LENGTH

OSS_LENGTH

OSS_HOST

OSS_HOST

OSS_DATE

OSS_DATE

OSS_AUTHORIZATION

OSS_AUTHORIZATION

OSS_FILE_DOWNLOAD

OSS_FILE_DOWNLOAD

OSS_FILE_UPLOAD

OSS_FILE_UPLOAD

OSS_PART_SIZE

OSS_PART_SIZE

OSS_SEEK_TO

OSS_SEEK_TO

OSS_SIZE

OSS_SIZE

OSS_QUERY_STRING

OSS_QUERY_STRING

OSS_SUB_RESOURCE

OSS_SUB_RESOURCE

OSS_DEFAULT_PREFIX

OSS_DEFAULT_PREFIX

OSS_CHECK_MD5

OSS_CHECK_MD5

DEFAULT_CONTENT_TYPE

DEFAULT_CONTENT_TYPE

OSS_URL_ACCESS_KEY_ID

OSS_URL_ACCESS_KEY_ID

OSS_URL_EXPIRES

OSS_URL_EXPIRES

OSS_URL_SIGNATURE

OSS_URL_SIGNATURE

OSS_HTTP_GET

OSS_HTTP_GET

OSS_HTTP_PUT

OSS_HTTP_PUT

OSS_HTTP_HEAD

OSS_HTTP_HEAD

OSS_HTTP_POST

OSS_HTTP_POST

OSS_HTTP_DELETE

OSS_HTTP_DELETE

OSS_HTTP_OPTIONS

OSS_HTTP_OPTIONS

OSS_ACL

OSS_ACL

OSS_OBJECT_ACL

OSS_OBJECT_ACL

OSS_OBJECT_GROUP

OSS_OBJECT_GROUP

OSS_MULTI_PART

OSS_MULTI_PART

OSS_MULTI_DELETE

OSS_MULTI_DELETE

OSS_OBJECT_COPY_SOURCE

OSS_OBJECT_COPY_SOURCE

OSS_OBJECT_COPY_SOURCE_RANGE

OSS_OBJECT_COPY_SOURCE_RANGE

OSS_PROCESS

OSS_PROCESS

OSS_CALLBACK

OSS_CALLBACK

OSS_CALLBACK_VAR

OSS_CALLBACK_VAR

OSS_SECURITY_TOKEN

OSS_SECURITY_TOKEN

OSS_ACL_TYPE_PRIVATE

OSS_ACL_TYPE_PRIVATE

OSS_ACL_TYPE_PUBLIC_READ

OSS_ACL_TYPE_PUBLIC_READ

OSS_ACL_TYPE_PUBLIC_READ_WRITE

OSS_ACL_TYPE_PUBLIC_READ_WRITE

OSS_ENCODING_TYPE

OSS_ENCODING_TYPE

OSS_ENCODING_TYPE_URL

OSS_ENCODING_TYPE_URL

OSS_HOST_TYPE_NORMAL

OSS_HOST_TYPE_NORMAL

OSS_HOST_TYPE_IP

OSS_HOST_TYPE_IP

OSS_HOST_TYPE_SPECIAL

OSS_HOST_TYPE_SPECIAL

OSS_HOST_TYPE_CNAME

OSS_HOST_TYPE_CNAME

OSS_NAME

OSS_NAME

OSS_VERSION

OSS_VERSION

OSS_BUILD

OSS_BUILD

OSS_AUTHOR

OSS_AUTHOR

OSS_OPTIONS_ORIGIN

OSS_OPTIONS_ORIGIN

OSS_OPTIONS_REQUEST_METHOD

OSS_OPTIONS_REQUEST_METHOD

OSS_OPTIONS_REQUEST_HEADERS

OSS_OPTIONS_REQUEST_HEADERS

Properties

$OSS_ACL_TYPES

$OSS_ACL_TYPES : 

Type

$useSSL

$useSSL : 

Type

$maxRetries

$maxRetries : 

Type

$redirects

$redirects : 

Type

$hostType

$hostType : 

Type

$requestUrl

$requestUrl : 

Type

$accessKeyId

$accessKeyId : 

Type

$accessKeySecret

$accessKeySecret : 

Type

$hostname

$hostname : 

Type

$securityToken

$securityToken : 

Type

$enableStsInUrl

$enableStsInUrl : 

Type

$timeout

$timeout : 

Type

$connectTimeout

$connectTimeout : 

Type

Methods

__construct()

__construct(string  $accessKeyId, string  $accessKeySecret, string  $endpoint, boolean  $isCName = false, string  $securityToken = NULL) 

构造函数

构造函数有几种情况:

  1. 一般的时候初始化使用 $ossClient = new OssClient($id, $key, $endpoint)
  2. 如果使用CNAME的,比如使用的是www.testoss.com,在控制台上做了CNAME的绑定, 初始化使用 $ossClient = new OssClient($id, $key, $endpoint, true)
  3. 如果使用了阿里云SecurityTokenService(STS),获得了AccessKeyID, AccessKeySecret, Token 初始化使用 $ossClient = new OssClient($id, $key, $endpoint, false, $token)
  4. 如果用户使用的endpoint是ip 初始化使用 $ossClient = new OssClient($id, $key, “1.2.3.4:8900”)

Parameters

string $accessKeyId

从OSS获得的AccessKeyId

string $accessKeySecret

从OSS获得的AccessKeySecret

string $endpoint

您选定的OSS数据中心访问域名,例如oss-cn-hangzhou.aliyuncs.com

boolean $isCName

是否对Bucket做了域名绑定,并且Endpoint参数填写的是自己的域名

string $securityToken

Throws

\OSS\Core\OssException

listBuckets()

listBuckets(array  $options = NULL) : \OSS\Model\BucketListInfo

列举用户所有的Bucket[GetService], Endpoint类型为cname不能进行此操作

Parameters

array $options

Throws

\OSS\Core\OssException

Returns

\OSS\Model\BucketListInfo

createBucket()

createBucket(string  $bucket, string  $acl = self::OSS_ACL_TYPE_PRIVATE, array  $options = NULL) : null

创建bucket,默认创建的bucket的ACL是OssClient::OSS_ACL_TYPE_PRIVATE

Parameters

string $bucket
string $acl
array $options

Returns

null

deleteBucket()

deleteBucket(string  $bucket, array  $options = NULL) : null

删除bucket 如果Bucket不为空(Bucket中有Object,或者有分块上传的碎片),则Bucket无法删除, 必须删除Bucket中的所有Object以及碎片后,Bucket才能成功删除。

Parameters

string $bucket
array $options

Returns

null

doesBucketExist()

doesBucketExist(string  $bucket) : boolean

判断bucket是否存在

Parameters

string $bucket

Throws

\OSS\Core\OssException

Returns

boolean

getBucketAcl()

getBucketAcl(string  $bucket, array  $options = NULL) : string

获取bucket的ACL配置情况

Parameters

string $bucket
array $options

Throws

\OSS\Core\OssException

Returns

string

putBucketAcl()

putBucketAcl(string  $bucket, string  $acl, array  $options = NULL) : null

设置bucket的ACL配置情况

Parameters

string $bucket

bucket名称

string $acl

读写权限,可选值 ['private', 'public-read', 'public-read-write']

array $options

可以为空

Throws

\OSS\Core\OssException

Returns

null

getObjectAcl()

getObjectAcl(string  $bucket, string  $object) : string

获取object的ACL属性

Parameters

string $bucket
string $object

Throws

\OSS\Core\OssException

Returns

string

putObjectAcl()

putObjectAcl(string  $bucket, string  $object, string  $acl) : null

设置object的ACL属性

Parameters

string $bucket

bucket名称

string $object

object名称

string $acl

读写权限,可选值 ['default', 'private', 'public-read', 'public-read-write']

Throws

\OSS\Core\OssException

Returns

null

getBucketLogging()

getBucketLogging(string  $bucket, array  $options = NULL) : \OSS\Model\LoggingConfig

获取Bucket的访问日志配置情况

Parameters

string $bucket

bucket名称

array $options

可以为空

Throws

\OSS\Core\OssException

Returns

\OSS\Model\LoggingConfig

putBucketLogging()

putBucketLogging(string  $bucket, string  $targetBucket, string  $targetPrefix, array  $options = NULL) : null

开启Bucket访问日志记录功能,只有Bucket的所有者才能更改

Parameters

string $bucket

bucket名称

string $targetBucket

日志文件存放的bucket

string $targetPrefix

日志的文件前缀

array $options

可以为空

Throws

\OSS\Core\OssException

Returns

null

deleteBucketLogging()

deleteBucketLogging(string  $bucket, array  $options = NULL) : null

关闭bucket访问日志记录功能

Parameters

string $bucket

bucket名称

array $options

可以为空

Throws

\OSS\Core\OssException

Returns

null

putBucketWebsite()

putBucketWebsite(string  $bucket, \OSS\Model\WebsiteConfig  $websiteConfig, array  $options = NULL) : null

将bucket设置成静态网站托管模式

Parameters

string $bucket

bucket名称

\OSS\Model\WebsiteConfig $websiteConfig
array $options

可以为空

Throws

\OSS\Core\OssException

Returns

null

getBucketWebsite()

getBucketWebsite(string  $bucket, array  $options = NULL) : \OSS\Model\WebsiteConfig

获取bucket的静态网站托管状态

Parameters

string $bucket

bucket名称

array $options

Throws

\OSS\Core\OssException

Returns

\OSS\Model\WebsiteConfig

deleteBucketWebsite()

deleteBucketWebsite(string  $bucket, array  $options = NULL) : null

关闭bucket的静态网站托管模式

Parameters

string $bucket

bucket名称

array $options

Throws

\OSS\Core\OssException

Returns

null

putBucketCors()

putBucketCors(string  $bucket, \OSS\Model\CorsConfig  $corsConfig, array  $options = NULL) : null

在指定的bucket上设定一个跨域资源共享(CORS)的规则,如果原规则存在则覆盖原规则

Parameters

string $bucket

bucket名称

\OSS\Model\CorsConfig $corsConfig

跨域资源共享配置,具体规则参见SDK文档

array $options

array

Throws

\OSS\Core\OssException

Returns

null

getBucketCors()

getBucketCors(string  $bucket, array  $options = NULL) : \OSS\Model\CorsConfig

获取Bucket的CORS配置情况

Parameters

string $bucket

bucket名称

array $options

可以为空

Throws

\OSS\Core\OssException

Returns

\OSS\Model\CorsConfig

deleteBucketCors()

deleteBucketCors(string  $bucket, array  $options = NULL) : null

关闭指定Bucket对应的CORS功能并清空所有规则

Parameters

string $bucket

bucket名称

array $options

Throws

\OSS\Core\OssException

Returns

null

addBucketCname()

addBucketCname(string  $bucket, string  $cname, array  $options = NULL) : null

为指定Bucket增加CNAME绑定

Parameters

string $bucket

bucket名称

string $cname
array $options

Throws

\OSS\Core\OssException

Returns

null

getBucketCname()

getBucketCname(string  $bucket, array  $options = NULL) : \OSS\Model\CnameConfig

获取指定Bucket已绑定的CNAME列表

Parameters

string $bucket

bucket名称

array $options

Throws

\OSS\Core\OssException

Returns

\OSS\Model\CnameConfig

deleteBucketCname()

deleteBucketCname(string  $bucket,   $cname, array  $options = NULL) : null

解除指定Bucket的CNAME绑定

Parameters

string $bucket

bucket名称

$cname
array $options

Throws

\OSS\Core\OssException

Returns

null

putBucketLiveChannel()

putBucketLiveChannel(string  $bucket,   $channelName, \OSS\Model\LiveChannelConfig  $channelConfig, array  $options = NULL) : \OSS\Model\LiveChannelInfo

为指定Bucket创建LiveChannel

Parameters

string $bucket

bucket名称

$channelName
\OSS\Model\LiveChannelConfig $channelConfig
array $options

Throws

\OSS\Core\OssException

Returns

\OSS\Model\LiveChannelInfo

putLiveChannelStatus()

putLiveChannelStatus(string  $bucket,   $channelName,   $channelStatus, array  $options = NULL) : null

设置LiveChannel的status

Parameters

string $bucket

bucket名称

$channelName
$channelStatus
array $options

Throws

\OSS\Core\OssException

Returns

null

getLiveChannelInfo()

getLiveChannelInfo(string  $bucket,   $channelName, array  $options = NULL) : \OSS\GetLiveChannelInfo

获取LiveChannel信息

Parameters

string $bucket

bucket名称

$channelName
array $options

Throws

\OSS\Core\OssException

Returns

\OSS\GetLiveChannelInfo

getLiveChannelStatus()

getLiveChannelStatus(string  $bucket,   $channelName, array  $options = NULL) : \OSS\GetLiveChannelStatus

获取LiveChannel状态信息

Parameters

string $bucket

bucket名称

$channelName
array $options

Throws

\OSS\Core\OssException

Returns

\OSS\GetLiveChannelStatus

getLiveChannelHistory()

getLiveChannelHistory(string  $bucket,   $channelName, array  $options = NULL) : \OSS\GetLiveChannelHistory

获取LiveChannel推流记录

Parameters

string $bucket

bucket名称

$channelName
array $options

Throws

\OSS\Core\OssException

Returns

\OSS\GetLiveChannelHistory

listBucketLiveChannels()

listBucketLiveChannels(string  $bucket, array  $options = NULL) : \OSS\Model\LiveChannelListInfo

获取指定Bucket下的live channel列表

Parameters

string $bucket

bucket名称

array $options

Throws

\OSS\Core\OssException

Returns

\OSS\Model\LiveChannelListInfo

postVodPlaylist()

postVodPlaylist(string  $bucket,   $channelName, string  $playlistName, array  $setTime) : null

为指定LiveChannel生成播放列表

Parameters

string $bucket

bucket名称

$channelName
string $playlistName

指定生成的点播播放列表的名称,必须以“.m3u8”结尾

array $setTime

startTime和EndTime以unix时间戳格式给定,跨度不能超过一天

Throws

\OSS\Core\OssException

Returns

null

deleteBucketLiveChannel()

deleteBucketLiveChannel(string  $bucket,   $channelName, array  $options = NULL) : null

删除指定Bucket的LiveChannel

Parameters

string $bucket

bucket名称

$channelName
array $options

Throws

\OSS\Core\OssException

Returns

null

signRtmpUrl()

signRtmpUrl(string  $bucket,   $channelName,   $timeout = 60, array  $options = NULL) : \OSS\推流地址

生成带签名的推流地址

Parameters

string $bucket

bucket名称

$channelName
$timeout
array $options

Throws

\OSS\Core\OssException

Returns

\OSS\推流地址

optionsObject()

optionsObject(string  $bucket, string  $object, string  $origin, string  $request_method, string  $request_headers, array  $options = NULL) : array

检验跨域资源请求, 发送跨域请求之前会发送一个preflight请求(OPTIONS)并带上特定的来源域, HTTP方法和header信息等给OSS以决定是否发送真正的请求。 OSS可以通过putBucketCors接口 来开启Bucket的CORS支持,开启CORS功能之后,OSS在收到浏览器preflight请求时会根据设定的 规则评估是否允许本次请求

Parameters

string $bucket

bucket名称

string $object

object名称

string $origin

请求来源域

string $request_method

表明实际请求中会使用的HTTP方法

string $request_headers

表明实际请求中会使用的除了简单头部之外的headers

array $options

Throws

\OSS\Core\OssException

Returns

array

putBucketLifecycle()

putBucketLifecycle(string  $bucket, \OSS\Model\LifecycleConfig  $lifecycleConfig, array  $options = NULL) : null

设置Bucket的Lifecycle配置

Parameters

string $bucket

bucket名称

\OSS\Model\LifecycleConfig $lifecycleConfig

Lifecycle配置类

array $options

Throws

\OSS\Core\OssException

Returns

null

getBucketLifecycle()

getBucketLifecycle(string  $bucket, array  $options = NULL) : \OSS\Model\LifecycleConfig

获取Bucket的Lifecycle配置情况

Parameters

string $bucket

bucket名称

array $options

Throws

\OSS\Core\OssException

Returns

\OSS\Model\LifecycleConfig

deleteBucketLifecycle()

deleteBucketLifecycle(string  $bucket, array  $options = NULL) : null

删除指定Bucket的生命周期配置

Parameters

string $bucket

bucket名称

array $options

Throws

\OSS\Core\OssException

Returns

null

putBucketReferer()

putBucketReferer(string  $bucket, \OSS\Model\RefererConfig  $refererConfig, array  $options = NULL) : \OSS\Http\ResponseCore

设置一个bucket的referer访问白名单和是否允许referer字段为空的请求访问 Bucket Referer防盗链具体见OSS防盗链

Parameters

string $bucket

bucket名称

\OSS\Model\RefererConfig $refererConfig
array $options

Throws

null

Returns

\OSS\Http\ResponseCore

getBucketReferer()

getBucketReferer(string  $bucket, array  $options = NULL) : \OSS\Model\RefererConfig

获取Bucket的Referer配置情况 Bucket Referer防盗链具体见OSS防盗链

Parameters

string $bucket

bucket名称

array $options

Throws

\OSS\Core\OssException

Returns

\OSS\Model\RefererConfig

listObjects()

listObjects(string  $bucket, array  $options = NULL) : \OSS\Model\ObjectListInfo

获取bucket下的object列表

Parameters

string $bucket
array $options

其中options中的参数如下 $options = array( 'max-keys' => max-keys用于限定此次返回object的最大数,如果不设定,默认为100,max-keys取值不能大于1000。 'prefix' => 限定返回的object key必须以prefix作为前缀。注意使用prefix查询时,返回的key中仍会包含prefix。 'delimiter' => 是一个用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现delimiter字符之间的object作为一组元素 'marker' => 用户设定结果从marker之后按字母排序的第一个开始返回。 ) 其中 prefix,marker用来实现分页显示效果,参数的长度必须小于256字节。

Throws

\OSS\Core\OssException

Returns

\OSS\Model\ObjectListInfo

createObjectDir()

createObjectDir(string  $bucket, string  $object, array  $options = NULL) : null

创建虚拟目录 (本函数会在object名称后增加'/', 所以创建目录的object名称不需要'/'结尾,否则,目录名称会变成'//')

暂不开放此接口

Parameters

string $bucket

bucket名称

string $object

object名称

array $options

Returns

null

putObject()

putObject(string  $bucket, string  $object, string  $content, array  $options = NULL) : null

上传内存中的内容

Parameters

string $bucket

bucket名称

string $object

objcet名称

string $content

上传的内容

array $options

Returns

null

uploadFile()

uploadFile(string  $bucket, string  $object, string  $file, array  $options = NULL) : null

上传本地文件

Parameters

string $bucket

bucket名称

string $object

object名称

string $file

本地文件路径

array $options

Throws

\OSS\Core\OssException

Returns

null

appendObject()

appendObject(string  $bucket, string  $object, string  $content,   $position, array  $options = NULL) : integer

追加上传内存中的内容

Parameters

string $bucket

bucket名称

string $object

objcet名称

string $content

本次追加上传的内容

$position
array $options

Throws

\OSS\Core\OssException

Returns

integer —

next append position

appendFile()

appendFile(string  $bucket, string  $object, string  $file,   $position, array  $options = NULL) : integer

追加上传本地文件

Parameters

string $bucket

bucket名称

string $object

object名称

string $file

追加上传的本地文件路径

$position
array $options

Throws

\OSS\Core\OssException

Returns

integer —

next append position

copyObject()

copyObject(string  $fromBucket, string  $fromObject, string  $toBucket, string  $toObject, array  $options = NULL) : null

拷贝一个在OSS上已经存在的object成另外一个object

Parameters

string $fromBucket

源bucket名称

string $fromObject

源object名称

string $toBucket

目标bucket名称

string $toObject

目标object名称

array $options

Throws

\OSS\Core\OssException

Returns

null

getObjectMeta()

getObjectMeta(string  $bucket, string  $object, string  $options = NULL) : array

获取Object的Meta信息

Parameters

string $bucket

bucket名称

string $object

object名称

string $options

具体参考SDK文档

Returns

array

deleteObject()

deleteObject(string  $bucket, string  $object, array  $options = NULL) : null

删除某个Object

Parameters

string $bucket

bucket名称

string $object

object名称

array $options

Returns

null

deleteObjects()

deleteObjects(string  $bucket, array  $objects, array  $options = null) : \OSS\Http\ResponseCore

删除同一个Bucket中的多个Object

Parameters

string $bucket

bucket名称

array $objects

object列表

array $options

Throws

null

Returns

\OSS\Http\ResponseCore

getObject()

getObject(string  $bucket, string  $object, array  $options = NULL) : string

获得Object内容

Parameters

string $bucket

bucket名称

string $object

object名称

array $options

该参数中必须设置ALIOSS::OSS_FILE_DOWNLOAD,ALIOSS::OSS_RANGE可选,可以根据实际情况设置;如果不设置,默认会下载全部内容

Returns

string

doesObjectExist()

doesObjectExist(string  $bucket, string  $object, array  $options = NULL) : boolean

检测Object是否存在 通过获取Object的Meta信息来判断Object是否存在, 用户需要自行解析ResponseCore判断object是否存在

Parameters

string $bucket

bucket名称

string $object

object名称

array $options

Returns

boolean

generateMultiuploadParts()

generateMultiuploadParts(integer  $file_size, integer  $partSize = 5242880) : array

计算文件可以分成多少个part,以及每个part的长度以及起始位置 方法必须在 <upload_part()>中调用

Parameters

integer $file_size

文件大小

integer $partSize

part大小,默认5M

Returns

array —

An array 包含 key-value 键值对. Key 为 seekTolength.

initiateMultipartUpload()

initiateMultipartUpload(string  $bucket, string  $object, array  $options = NULL) : string

初始化multi-part upload

Parameters

string $bucket

Bucket名称

string $object

Object名称

array $options

Key-Value数组

Throws

\OSS\Core\OssException

Returns

string —

返回uploadid

uploadPart()

uploadPart(string  $bucket, string  $object, string  $uploadId, array  $options = null) : string

分片上传的块上传接口

Parameters

string $bucket

Bucket名称

string $object

Object名称

string $uploadId
array $options

Key-Value数组

Throws

\OSS\Core\OssException

Returns

string —

eTag

listParts()

listParts(string  $bucket, string  $object, string  $uploadId, array  $options = null) : \OSS\Model\ListPartsInfo

获取已成功上传的part

Parameters

string $bucket

Bucket名称

string $object

Object名称

string $uploadId

uploadId

array $options

Key-Value数组

Throws

\OSS\Core\OssException

Returns

\OSS\Model\ListPartsInfo

abortMultipartUpload()

abortMultipartUpload(string  $bucket, string  $object, string  $uploadId, array  $options = NULL) : null

中止进行一半的分片上传操作

Parameters

string $bucket

Bucket名称

string $object

Object名称

string $uploadId

uploadId

array $options

Key-Value数组

Throws

\OSS\Core\OssException

Returns

null

completeMultipartUpload()

completeMultipartUpload(string  $bucket, string  $object, string  $uploadId, array  $listParts, array  $options = NULL) : null

在将所有数据Part都上传完成后,调用此接口完成本次分块上传

Parameters

string $bucket

Bucket名称

string $object

Object名称

string $uploadId

uploadId

array $listParts

array( array("PartNumber"=> int, "ETag"=>string))

array $options

Key-Value数组

Throws

\OSS\Core\OssException

Returns

null

listMultipartUploads()

listMultipartUploads(string  $bucket, array  $options = null) : \OSS\Model\ListMultipartUploadInfo

罗列出所有执行中的Multipart Upload事件,即已经被初始化的Multipart Upload但是未被 Complete或者Abort的Multipart Upload事件

Parameters

string $bucket

bucket

array $options

关联数组

Throws

\OSS\Core\OssException

Returns

\OSS\Model\ListMultipartUploadInfo

uploadPartCopy()

uploadPartCopy(string  $fromBucket, string  $fromObject, string  $toBucket, string  $toObject, integer  $partNumber, string  $uploadId, array  $options = NULL) : null

从一个已存在的Object中拷贝数据来上传一个Part

Parameters

string $fromBucket

源bucket名称

string $fromObject

源object名称

string $toBucket

目标bucket名称

string $toObject

目标object名称

integer $partNumber

分块上传的块id

string $uploadId

初始化multipart upload返回的uploadid

array $options

Key-Value数组

Throws

\OSS\Core\OssException

Returns

null

multiuploadFile()

multiuploadFile(string  $bucket, string  $object, string  $file, array  $options = null) : null

multipart上传统一封装,从初始化到完成multipart,以及出错后中止动作

Parameters

string $bucket

bucket名称

string $object

object名称

string $file

需要上传的本地文件的路径

array $options

Key-Value数组

Throws

\OSS\Core\OssException

Returns

null

uploadDir()

uploadDir(string  $bucket, string  $prefix, string  $localDirectory, string  $exclude = '.|..|.svn|.git', boolean  $recursive = false, boolean  $checkMd5 = true) : array

上传本地目录内的文件或者目录到指定bucket的指定prefix的object中

Parameters

string $bucket

bucket名称

string $prefix

需要上传到的object的key前缀,可以理解成bucket中的子目录,结尾不能是'/',接口中会补充'/'

string $localDirectory

需要上传的本地目录

string $exclude

需要排除的目录

boolean $recursive

是否递归的上传localDirectory下的子目录内容

boolean $checkMd5

Throws

\OSS\Core\OssException

Returns

array —

返回两个列表 array("succeededList" => array("object"), "failedList" => array("object"=>"errorMessage"))

signUrl()

signUrl(string  $bucket, string  $object, integer  $timeout = 60, string  $method = self::OSS_HTTP_GET, array  $options = NULL) : string

支持生成get和put签名, 用户可以生成一个具有一定有效期的 签名过的url

Parameters

string $bucket
string $object
integer $timeout
string $method
array $options

Key-Value数组

Throws

\OSS\Core\OssException

Returns

string

setMaxTries()

setMaxTries(integer  $maxRetries = 3) : void

设置最大尝试次数

Parameters

integer $maxRetries

getMaxRetries()

getMaxRetries() : integer

获取最大尝试次数

Returns

integer

setSignStsInUrl()

setSignStsInUrl(boolean  $enable) 

打开sts enable标志,使用户构造函数中传入的$sts生效

Parameters

boolean $enable

isUseSSL()

isUseSSL() : boolean

Returns

boolean

setUseSSL()

setUseSSL(boolean  $useSSL) 

Parameters

boolean $useSSL

checkEnv()

checkEnv() 

用来检查sdk所以来的扩展是否打开

Throws

\OSS\Core\OssException

setTimeout()

setTimeout(integer  $timeout) 

//* 设置http库的请求超时时间,单位秒

Parameters

integer $timeout

setConnectTimeout()

setConnectTimeout(integer  $connectTimeout) 

设置http库的连接超时时间,单位秒

Parameters

integer $connectTimeout

computePartSize()

computePartSize(integer  $partSize) : integer

获取分片大小,根据用户提供的part_size,重新计算一个更合理的partsize

Parameters

integer $partSize

Returns

integer

precheckOptions()

precheckOptions(array  $options) 

检测options参数

Parameters

array $options

Throws

\OSS\Core\OssException

precheckBucket()

precheckBucket(string  $bucket, string  $errMsg = 'bucket is not allowed empty') 

校验bucket参数

Parameters

string $bucket
string $errMsg

Throws

\OSS\Core\OssException

precheckObject()

precheckObject(string  $object) 

校验object参数

Parameters

string $object

Throws

\OSS\Core\OssException

precheckCommon()

precheckCommon(string  $bucket, string  $object, array  $options, boolean  $isCheckObject = true) 

校验bucket,options参数

Parameters

string $bucket
string $object
array $options
boolean $isCheckObject

precheckParam()

precheckParam(array  $options, string  $param, string  $funcName) 

参数校验

Parameters

array $options
string $param
string $funcName

Throws

\OSS\Core\OssException

isCheckMD5()

isCheckMD5(array  $options) : boolean|null

检测md5

Parameters

array $options

Returns

boolean|null

getValue()

getValue(array  $options, string  $key, string  $default = NULL, boolean  $isCheckEmpty = false, boolean  $isCheckBool = false) : boolean|null

获取value

Parameters

array $options
string $key
string $default
boolean $isCheckEmpty
boolean $isCheckBool

Returns

boolean|null

getMimeType()

getMimeType(string  $object,   $file = null) : string

获取mimetype类型

Parameters

string $object
$file

Returns

string

auth()

auth(array  $options) : \OSS\Http\ResponseCore

验证并且执行请求,按照OSS Api协议,执行操作

Parameters

array $options

Throws

\OSS\Core\OssException
\OSS\Http\RequestCore_Exception

Returns

\OSS\Http\ResponseCore

authPrecheckBucket()

authPrecheckBucket(  $options) 

检查bucket名称格式是否正确,如果非法抛出异常

Parameters

$options

Throws

\OSS\Core\OssException

authPrecheckObject()

authPrecheckObject(  $options) 

检查object名称格式是否正确,如果非法抛出异常

Parameters

$options

Throws

\OSS\Core\OssException

authPrecheckObjectEncoding()

authPrecheckObjectEncoding(mixed  $options) 

检查object的编码,如果是gbk或者gb2312则尝试将其转化为utf8编码

Parameters

mixed $options

参数

authPrecheckAcl()

authPrecheckAcl(  $options) 

检查ACL是否是预定义中三种之一,如果不是抛出异常

Parameters

$options

Throws

\OSS\Core\OssException

generateHostname()

generateHostname(  $bucket) : string

获得档次请求使用的域名 bucket在前的三级域名,或者二级域名,如果是cname或者ip的话,则是二级域名

Parameters

$bucket

Returns

string —

剥掉协议头的域名

generateResourceUri()

generateResourceUri(  $options) : string

获得当次请求的资源定位字段

Parameters

$options

Returns

string —

资源定位字段

generateSignableQueryStringParam()

generateSignableQueryStringParam(array  $options) : array

生成signalbe_query_string_param, array类型

Parameters

array $options

Returns

array

generateSignableResource()

generateSignableResource(mixed  $options) : string

生成用于签名resource段

Parameters

mixed $options

Returns

string

generateQueryString()

generateQueryString(mixed  $options) : string

生成query_string

Parameters

mixed $options

Returns

string

stringToSignSorted()

stringToSignSorted(  $string_to_sign) 

Parameters

$string_to_sign

generateHeaders()

generateHeaders(mixed  $options, string  $hostname) : array

初始化headers

Parameters

mixed $options
string $hostname

hostname

Returns

array

generateUserAgent()

generateUserAgent() : string

生成请求用的UserAgent

Returns

string

checkEndpoint()

checkEndpoint(string  $endpoint, boolean  $isCName) : string

检查endpoint的种类 如有有协议头,剥去协议头 并且根据参数 is_cname 和endpoint本身,判定域名类型,是ip,cname,还是专有域或者官网域名

Parameters

string $endpoint
boolean $isCName

Returns

string —

剥掉协议头的域名