生成带授权信息的URL
功能说明
通过访问密钥、请求方法类型、请求参数等信息生成一个在Query参数中携带鉴权信息的URL,以对OBS服务进行特定操作。
方法定义
ObsClient->createSignedUrl(array $parameter)
请求参数
字段名 |
类型 |
约束 |
说明 |
---|---|---|---|
Method |
string |
必选 |
HTTP方法类型,支持的值:
|
Bucket |
string |
可选 |
桶名。 |
Key |
string |
可选 |
对象名。 |
SpecialParam |
string |
可选 |
特殊操作符,代表要操作的子资源,支持的值:
|
Expires |
integer |
可选 |
带授权信息的URL的过期时间(单位:秒),默认值:300。 |
Headers |
associative array |
可选 |
请求中携带的头域。 |
QueryParams |
associative array |
可选 |
请求中携带的查询参数。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
SignedUrl |
string |
带授权信息的URL。 |
ActualSignedRequestHeaders |
associative array |
通过带授权信息的URL发起请求时实际应携带的头域。 |
代码样例
try { // 生成创建桶的带授权信息的URL $resp = $obsClient->createSignedUrl( [ 'Method' => 'PUT', 'Bucket' => 'bucketname', 'Expires' => 3600, ] ); printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] ); printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) ); // 生成上传对象的带授权信息的URL $resp = $obsClient->createSignedUrl( [ 'Method' => 'PUT', 'Bucket' => 'bucketname', 'Key' => 'objectkey', 'Expires' => 3600, 'Headers' => ['content-type' => 'text/plain'] ] ); printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] ); printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) ); // 生成设置对象ACL的带授权信息的URL $resp = $obsClient->createSignedUrl( [ 'Method' => 'PUT', 'Bucket' => 'bucketname', 'Key' => 'objectkey', 'Expires' => 3600, 'SpecialParam' => 'acl', 'Headers' => ['x-obs-acl' => 'public-read'] ] ); printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] ); printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) ); // 生成下载对象的带授权信息的URL $resp = $obsClient->createSignedUrl( [ 'Method' => 'GET', 'Bucket' => 'bucketname', 'Key' => 'objectkey', 'Expires' => 3600 ] ); printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] ); printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) ); // 生成删除对象的带授权信息的URL $resp = $obsClient->createSignedUrl( [ 'Method' => 'DELETE', 'Bucket' => 'bucketname', 'Key' => 'objectkey', 'Expires' => 3600 ] ); printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] ); printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) ); // 生成删除桶的带授权信息的URL $resp = $obsClient->createSignedUrl( [ 'Method' => 'DELETE', 'Bucket' => 'bucketname', 'Expires' => 3600 ] ); printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] ); printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) ); } catch ( Obs\Common\ObsException $obsException ) { printf ( "ExceptionCode:%s\n", $obsException->getExceptionCode () ); printf ( "ExceptionMessage:%s\n", $obsException->getExceptionMessage () ); }