You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Browser.js
Installing the Browser.js SDK
Copy page
Download PDF
Installing the Browser.js SDK
This article outlines the preparatory steps and installation procedures for the Browser.js SDK.​
Preparatory Work​
  • When accessing TOS directly via a browser, the CORS configuration rules are required as follows:​
  • ​
    Parameter​
    Description​
    Origin​
    Set a precise domain name (for example, https://console.volcengine.com) or a wildcard asterisk (*).​
    Operation methods​
    Please select different Methods according to the actual usage scenario. For example, set to PUT when performing multipart uploads; set to DELETE when deleting files.​
    Allow-Headers​
    Set to* ​
    Expose-Headers​
    Set to ETag, x-tos-request-id, and x-tos-version-id.​
    ​
  • ​
SDK Download Link​
TOS Browser.js SDK source code address: please refer to TOS Browser.js SDK.​
Supported Browsers​
The following browsers are supported by the TOS Browser.js SDK:​
  • Internet Explorer version 10 and above​
  • Edge​
  • Mainstream versions of Chrome, Firefox, and Safari​
  • Default browsers of mainstream versions of the Android, iOS, and Windows Phone operating systems​
Notes​
Due to the specific constraints of the browser environment, the TOS Browser.js SDK cannot utilize the following features:​
  • Operating Local Files: Browsers cannot directly access the local file system. It is recommended to use pre-signed URLs to download files.​
  • Since TOS temporarily does not support cross-origin requests related to Buckets, it is recommended that you perform Bucket-related operations in the TOS Console.​
Install the SDK​
Browser Introduction​
warning​
  • As some browsers do not support Promise, you need to include a Promise compatibility library during installation. For example, IE10 and IE11 require the inclusion of promise-polyfill.​
  • The method of incorporating online resources relies on the stability of CDN servers. Therefore, it is recommended to adopt offline integration, either by utilizing local resources or by building the resources independently.​
  • Introduction of Online Resources​
  • ​
    <script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>​
    ​
  • Incorporating local resources​
  • ​
    <script src="./tos.umd.production.min.js"></script>​
    ​
Utilize the TOS object in the code.​
​
<script type="text/javascript">​
const client = new TOS({​
accessKeyId: 'Your Access Key',​
accessKeySecret: 'Your Secret Key',​
stsToken: 'Your Session Token',​
region: 'Your Region',​
bucket: 'Your Bucket',​
});​
</script>​
​
Installing the SDK via npm or yarn​
  • Install using npm​
  • ​
    npm i @volcengine/tos-sdk​
    ​
  • Install using yarn​
  • ​
    yarn add @volcengine/tos-sdk​
    ​
After successful installation, you can use import or require to import. You can use the following commands to import the SDK. Note that there are differences between importing modules using ES6 import statements and CommonJS (CJS) import commands.​
warning​
When using import or require, you need to use relevant bundling tools in the development environment, such as webpack, browserify, etc.​
  • Use import to perform an import​
  • ​
    import TOS from '@volcengine/tos-sdk';​
    ​
  • Use require to import​
  • ​
    const { TOS } = require('@volcengine/tos-sdk');​
    ​
Use the TOS object in the code.​
​
<script type="text/javascript">​
const client = new TOS({​
accessKeyId: 'Your Access Key',​
accessKeySecret: 'Your Secret Key',​
stsToken: 'Your Session Token',​
region: 'Your Region',​
bucket: 'Your Bucket',​
});​
</script>​
​
​
Last updated: 2025.09.22 18:55:46