All Products
Search
Document Center

Object Storage Service:Initialization

Last Updated:Sep 19, 2023

This topic describes the parameters that you can configure when you initialize Object Storage Service (OSS) SDK for Browser.js and provides examples on how to initialize OSS SDK for Browser.js.

Prerequisites

OSS SDK for Browser.js is installed. For more information, see Installation.

Parameters

The following table describes the parameters for initialization of OSS SDK for Browser.js.

Parameter

Type

Description

accessKeyId

String

The AccessKey ID of the Alibaba Cloud account or RAM user, or AccessKey ID included in temporary access credentials that are issued by Security Token Service (STS).

accessKeySecret

String

The AccessKey secret of the Alibaba Cloud account or RAM user, or AccessKey secret included in temporary access credentials that are issued by STS.

stsToken

String

The security token obtained from STS. For more information, see the Use STS for temporary access authorization section of the "Authorize access" topic.

bucket

String

The name of the bucket. The bucket is created by using the OSS console or calling the PutBucket operation.

endpoint

String

The endpoint that is used to access OSS. The following types of endpoints are available: public endpoint, internal endpoint, custom domain name, and acceleration endpoint. For more information about regions and endpoints, see Regions and endpoints.

Important

If you use a custom domain name or an acceleration endpoint to access OSS, you must specify the endpoint parameter instead of the region parameter. For more information about how to specify the endpoint parameter, see Map custom domain names.

region

String

The region in which the bucket is located. Default value: oss-cn-hangzhou.

Important

If you use a public endpoint or an internal endpoint to access OSS, you must specify the region parameter instead of the endpoint parameter. For more information about how to configure the region parameter, see Simple upload.

internal

Boolean

Specifies whether to use the Alibaba Cloud internal network to access OSS. Default value: false. For example, set this parameter to true if you use an Elastic Compute Service (ECS) instance to access OSS. Access from an ECS instance uses an internal endpoint, which reduces costs.

cname

Boolean

Specifies whether a custom domain name can be used to access OSS. Default value: false. If you set cname to true, you must map the custom domain name to the bucket.

isRequestPay

Boolean

Specifies whether the pay-by-requester mode is enabled for your bucket. Default value: false. For more information, see Pay-by-requester.

secure

Boolean

The protocol over which OSS can be accessed. If you want to access OSS over HTTPS, set secure to true. If you want to access OSS over HTTP, set secure to false. For more information, see FAQ.

timeout

String|Number

The timeout period. Default value: 60000. Unit: milliseconds.

Configuration example

The following sample code provides an example on how to initialize OSS SDK for Browser.js:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
  </head>
  <body>
    <!-- Import the SDK file -->
    <script
      type="text/javascript"
      src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.18.0.min.js"
    ></script>
    <script type="text/javascript">
      const client = new OSS({
        // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
        region: 'yourRegion',
        // Specify the temporary AccessKey pair obtained from STS. The AccessKey pair consists of an AccessKey ID and an AccessKey secret. 
        accessKeyId: 'yourAccessKeyId',
        accessKeySecret: 'yourAccessKeySecret',
        // Specify the security token that you obtained from STS. 
        stsToken: 'yourSecurityToken',
        // Specify the name of the bucket. Example: examplebucket. 
        bucket: "examplebucket",
      });
    </script>
  </body>
</html>