Help Center> OBS PHP SDK> API Reference> Other APIs> Generating Browser-Based Upload Parameters with Authentication Information
Updated on 2022-02-10 GMT+08:00

Generating Browser-Based Upload Parameters with Authentication Information

API Description

You can use this API to generate parameters for authentication. The parameters can be used to upload data through POST operations based on a browser.

There are two request parameters generated:

  • Policy, which corresponds to the policy field in the form
  • Signature: which corresponds to the signature field in the form

Method Definition

ObsClient->createPostSignature(array $parameter)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Optional

Bucket name

Key

string

Optional

Object name, which corresponds to the key field in the form

Expires

integer

Optional

Validity period of the browser-based upload authentication, in seconds. The default value is 300.

FormParams

associative array

Optional

Other parameters of the browser-based upload except for key, policy, and signature. Possible values are:

  • acl
  • cache-control
  • content-type
  • content-disposition
  • content-encoding
  • expires

Returned Result

Field

Type

Description

OriginPolicy

String

Value of Policy that is not encoded by base64. This parameter can only be used for verification.

Policy

String

policy in the form

Signature

String

signature in the form

Sample Code

try {
       $resp = $obsClient->createPostSignature( [ 
              'Bucket' => 'bucketname',
              'Key' => 'objectkey',
              'Expires' => 3600,
              'FormParams' => [
                     'acl' => 'public-read',
                     'content-type' => 'text/plain',
              ]
       ] );
       printf ( "Policy:%s\n", $resp ['Policy'] );
       printf ( "Signature:%s\n", $resp ['Signature'] );
} catch ( Obs\Common\ObsException $obsException ) {
       printf ( "ExceptionCode:%s\n", $obsException->getExceptionCode () );
       printf ( "ExceptionMessage:%s\n", $obsException->getExceptionMessage () );
}