Creating a Signed URL
API Description
You can use this API to generate a URL whose Query parameters are carried with authentication information, by specifying the AK and SK, HTTP method, and request parameters. You can use a signed URL to perform specific operations on OBS.
Method Definition
ObsClient->createSignedUrl(array $parameter)
Request Parameter
Field |
Type |
Optional or Mandatory |
Description |
---|---|---|---|
Method |
string |
Mandatory |
HTTP method. Possible values are:
|
Bucket |
string |
Optional |
Bucket name |
Key |
string |
Optional |
Object name |
SpecialParam |
string |
Optional |
Special operator, which indicates the sub-resource to be operated. Possible values are:
|
Expires |
integer |
Optional |
Expiration time of the signed URL, in seconds. The default value is 300. |
Headers |
associative array |
Optional |
Headers in the request |
QueryParams |
associative array |
Optional |
Query parameters in the request |
Returned Result
Field |
Type |
Description |
---|---|---|
SignedUrl |
string |
Signed URL |
ActualSignedRequestHeaders |
associative array |
Actual headers in the request initiated by using the signed URL |
Sample Code
try { // Generate a signed URL for creating a bucket. $resp = $obsClient->createSignedUrl( [ 'Method' => 'PUT', 'Bucket' => 'bucketname', 'Expires' => 3600, ] ); printf ( "SignedUrl:%s\n", $resp ['SignedUrl'] ); printf ( "ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true) ); // Generate a signed URL for uploading an object. $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) ); // Generate a signed URL for setting an object ACL. $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) ); // Generate a signed URL for downloading an object. $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) ); // Generate a signed URL for deleting an object. $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) ); // Generate a signed URL for deleting a bucket. $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 () ); }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.