Static Website

Last updated: 2020-03-20 12:26:23

PDF

Note

This document provides an overview of API on static websites and sample SDK code.

API Operation name pedagogical operation
PUT Bucket website Setting up a Static Website Set Bucket's static website configuration
GET Bucket website Query static site configuration Query Bucket's static website configuration
DELETE Bucket website Delete static site configuration Delete Bucket's static website configuration

Setting up a Static Website

Function description

PUT Bucket website is used to configure a static website for Bucket.

Method prototype

PutBucketWebsiteResult putBucketWebsite(PutBucketWebsiteRequest request) throws CosXmlClientException, CosXmlServiceException;

void putBucketWebsiteAsync(PutBucketWebsiteRequest request,  CosXmlResultListener cosXmlResultListener);

Request Sample

String bucket = "examplebucket-1250000000"; 
PutBucketWebsiteRequest putBucketWebsiteRequest = new PutBucketWebsiteRequest(bucket);
putBucketWebsiteRequest.setIndexDocument("index.html");

try {
    PutBucketWebsiteResult putBucketWebsiteResult = cosXmlService.putBucketWebsite(putBucketWebsiteRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

cosXmlService.putBucketWebsiteAsync(putBucketWebsiteRequest, new CosXmlResultListener() {
    @Override
    public void onSuccess(CosXmlRequest request, CosXmlResult result) {
        PutBucketWebsiteResult putBucketWebsiteResult = (PutBucketWebsiteResult) result;
    }

    @Override
    public void onFail(CosXmlRequest cosXmlRequest, CosXmlClientException clientException, CosXmlServiceException serviceException)  {
    }
});

Parameter description

Parameter name Description Type
Bucket Set the Bucket of the static website in BucketName-APPID format. For more information, please see Naming convention String
IndexDocument Index document String
ErrorDocument Error document String
RedirectAllRequestTo Redirect all requests String
RoutingRules Redirection rule List

Return result description

Member variable Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) otherwise it failed Int

Query static site configuration

Function description

GET Bucket website is used to query static website configuration information with Bucket and Associate.

Method prototype

GetBucketWebsiteResult getBucketWebsite(GetBucketWebsiteRequest request)throws CosXmlClientException, CosXmlServiceException;

void getBucketWebsiteAsync(GetBucketWebsiteRequest request, CosXmlResultListener cosXmlResultListener);

Request Sample

String bucket = "examplebucket-1250000000"; 
GetBucketWebsiteRequest getBucketWebsiteRequest = new GetBucketWebsiteRequest(bucket);
Set<String> headerKeys = new HashSet<>();
headerKeys.add("Host");
getBucketWebsiteRequest.setSignParamsAndHeaders(null, headerKeys);
try {
    GetBucketWebsiteResult getBucketWebsiteResult = cosXmlService.getBucketWebsite(getBucketWebsiteRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

cosXmlService.getBucketWebsiteAsync(getBucketWebsiteRequest, new CosXmlResultListener() {
    @Override
    public void onSuccess(CosXmlRequest request, CosXmlResult result) {
        GetBucketWebsiteResult getBucketWebsiteResult = (GetBucketWebsiteResult)result;
    }

    @Override
    public void onFail(CosXmlRequest cosXmlRequest, CosXmlClientException clientException, CosXmlServiceException serviceException)  {
    }
});

Parameter description

Parameter name Description Type
Bucket Query Bucket configured on a static website in BucketName-APPID format. For more information, please see Naming convention String

Return result description

Member variable Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) otherwise it failed Int
WebsiteConfiguration Returns Bucket object WebsiteConfiguration information WebsiteConfiguration

Delete static site configuration

Function description

DELETE Bucket website is used to delete the static website configuration in Bucket.

Method prototype

DeleteBucketWebsiteResult deleteBucketWebsite(DeleteBucketWebsiteRequest request) throws CosXmlClientException, CosXmlServiceException;

void deleteBucketWebsiteAsync(DeleteBucketWebsiteRequest request, CosXmlResultListener cosXmlResultListener);

Request Sample

String bucket = "examplebucket-1250000000"; 
DeleteBucketWebsiteRequest deleteBucketWebsiteRequest = new DeleteBucketWebsiteRequest(bucket);
Set<String> headerKeys = new HashSet<>();
headerKeys.add("Host");
deleteBucketWebsiteRequest.setSignParamsAndHeaders(null, headerKeys);
try {
    DeleteBucketWebsiteResult deleteBucketWebsiteResult = cosXmlService.deleteBucketWebsite(deleteBucketWebsiteRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

cosXmlService.deleteBucketWebsiteAsync(deleteBucketWebsiteRequest, new CosXmlResultListener() {
    @Override
    public void onSuccess(CosXmlRequest request, CosXmlResult result) {
        DeleteBucketWebsiteResult getBucketWebsiteResult = (DeleteBucketWebsiteResult)result;
    }

    @Override
    public void onFail(CosXmlRequest cosXmlRequest, CosXmlClientException clientException, CosXmlServiceException serviceException)  {
    }
});

Parameter description

Parameter name Description Type
Bucket Bucket, whose static website configuration is deleted, is in BucketName-APPID format. For more information, please see Naming convention String

Return result description

Member variable Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) otherwise it failed Int