Cross-domain Access

Last updated: 2020-03-20 09:51:01

PDF

Note

This document provides an overview of API on cross-domain Access and sample SDK code.

API Operation name pedagogical operation
PUT Bucket cors Set cross-domain configuration Set up Bucket's cross-domain name Access and Permission
GET Bucket cors Query cross-domain configuration Query Bucket's cross-domain name Access configuration information
DELETE Bucket cors Delete cross-domain configuration Delete Bucket's cross-domain name Access configuration information

Set cross-domain configuration

Function description

Set the cross-domain name Access configuration information (PUT Bucket cors) of specified Bucket.

Method prototype

public Guzzle\Service\Resource\Model putBucketCors(array $args = array());

Request Sample

try {
    $result = $cosClient->putBucketCors(array(
        'Bucket' => 'examplebucket-1250000000', 
        'CORSRules' => array(
            array(
                'AllowedHeaders' => array('*',),
                'AllowedMethods' => array('PUT', ),
                'AllowedOrigins' => array('*', ),
                'ExposeHeaders' => array('*', ),
                'MaxAgeSeconds' => 1,
            ),  
            // ... repeated
        )   
    )); 
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}

Parameter description

Parameter name Type Description Required/Optional
Bucket String Set Bucket for cross-domain configuration, format: BucketName-APPID Yes
CORSRules Array Cross-domain information list Yes
CORSRule Array Cross-domain information Yes
AllowedMethods String Allowed HTTP operations. Enumerated values: GET,PUT,HEAD,POST,DELETE Yes
AllowedOrigins String Allowed Access source, supports wildcards * , format: Protocol://Domain[:Port] , for example http://www.qq.com Yes
AllowedHeaders String When sending a OPTIONS request, tell the server which custom HTTP request headers can be used for subsequent requests, and wildcards are supported. * No
ExposeHeaders String Set the browser to receive custom header information from the server No
MaxAgeSeconds Int Set the validity period of the result obtained by the OPTIONS request No
Id String Configure the ID of a rule Yes

Query cross-domain configuration

Function description

Query the cross-domain name Access configuration information (GET Bucket cors) of specified Bucket.

Method prototype

public Guzzle\Service\Resource\Model getBucketCors(array $args = array());

Request Sample

try {
    $result = $cosClient->getBucketCors(array(
        'Bucket' => 'examplebucket-1250000000' 
    )); 
    print_r($result);
} catch (\Exception $e) {
    echo($e);
}

Parameter description

Parameter name Type Description Required/Optional
Bucket String Query Bucket with cross-domain configuration. Format: BucketName-APPID Yes

Return an example of the result

Guzzle\Service\Resource\Model Object
(
    [data:protected] => Array
        (
            [CORSRules] => Array
                (
                    [0] => Array
                        (
                            [ID] => 1234
                            [AllowedHeaders] => Array
                                (
                                    [0] => *
                                )
                            [AllowedMethods] => Array
                                (
                                    [0] => PUT
                                )
                            [AllowedOrigins] => Array
                                (
                                    [0] => http://www.qq.com
                                )
                        )
                )
            [RequestId] => NWE3YzhkMmRfMTdiMjk0MGFfNTQzZl8xNWUw****
        )
)

Return result description

Parameter name Type Description Parent node
CORSRules Array Cross-domain information list None
CORSRule Array Cross-domain information CORSRules
AllowedMethods String Allowed HTTP operations. Enumerated values: GET,PUT,HEAD,POST,DELETE CORSRule
AllowedOrigins String Allowed Access source, supports wildcards * , format: Protocol: //Domain name[:Port] , for example http://www.qq.com CORSRule
AllowedHeaders String When sending a OPTIONS request, tell the server which custom HTTP request headers can be used for subsequent requests, and wildcards are supported. * CORSRule
ExposeHeaders String Set the browser to receive custom header information from the server CORSRule
MaxAgeSeconds Int Set the validity period of the result obtained by the OPTIONS request CORSRule
Id String Configure the ID of a rule CORSRule

Delete cross-domain configuration

Function description

Delete the cross-domain name Access configuration (DELETE Bucket cors) of the specified Bucket.

Method prototype

public Guzzle\Service\Resource\Model deleteBucketCors(array $args = array());

Request Sample

try {
    $result = $cosClient->deleteBucketCors(array(
        'Bucket' => 'examplebucket-1250000000' 
    )); 
    print_r($result);
} catch (\Exception $e) {
    echo($e);
}

Parameter description

Parameter name Type Description Required/Optional
Bucket String Bucket with deleted cross-domain configuration, format: BucketName-APPID Yes