• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (PHP SDK)
  4. Temporary Authentication
  5. Temporarily Authorized Request

Temporarily Authorized Request

You can call ObsClient->createV2SignedUrl to create a URL for a temporarily authorized request. The following sample code creates a URL for common operations, including bucket creation, as well as object upload, download, listing, and deletion.

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
              'key' => '*** Provide your Access Key ***',
              'secret' => '*** Provide your Secret Key ***',
              'endpoint' => 'https://yourdomainname'
] );

// Set the validity period of the URL to 3600 seconds.
$expires = 3600;
// Create a bucket.
$resp = $obsClient->createV2SignedUrl( [ 
              'Method' => 'PUT',
              'Bucket' => 'bucketname',
              'Expires' => $expires
] );
printf("SignedUrl:%s\n", $resp ['SignedUrl']);
printf("ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true));

// Upload an object.
$resp = $obsClient->createV2SignedUrl( [ 
              'Method' => 'PUT',
              'Bucket' => 'bucketname',
              'Key' => 'objectkey',
              'Headers' => [ 
                           'Content-Type' => 'text/plain' 
              ],
              'Expires' => $expires
] );
printf("SignedUrl:%s\n", $resp ['SignedUrl']);
printf("ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true));


// Download an object.
$resp = $obsClient->createV2SignedUrl( [ 
              'Method' => 'GET',
              'Bucket' => 'bucketname',
              'Key' => 'objectkey',
              'Expires' => $expires
] );
printf("SignedUrl:%s\n", $resp ['SignedUrl']);
printf("ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true));

// List objects.
$resp = $obsClient->createV2SignedUrl( [
              'Method' => 'GET',
              'Bucket' => 'bucketname',
              'Expires' => $expires
] );
printf("SignedUrl:%s\n", $resp ['SignedUrl']);
printf("ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true));

// Delete an object.
$resp = $obsClient->createV2SignedUrl( [ 
              'Method' => 'GET',
              'Bucket' => 'bucketname',
              'Key' => 'objectkey',
              'Expires' => $expires
] );
printf("SignedUrl:%s\n", $resp ['SignedUrl']);
printf("ActualSignedRequestHeaders:%s\n", print_r($resp ['ActualSignedRequestHeaders'], true));
NOTE:
  • Use the Method parameter to specify the HTTP request method, the Expires parameter to specify the validity period of the URL, the Headers parameter to specify the request headers, the SpecialParam parameter to specify the special operator, and the QueryParams parameter to specify the request parameters.