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

Torch Object Storage

Copy page
Download PDF
Accessing TOS with third-party tools
Accessing TOS with Flutter SDK
Copy page
Download PDF
Accessing TOS with Flutter SDK
The TOS Flutter SDK is now available on pub.dev. Use it to access TOS and upload or download your data. This topic uses Android Studio as an example to explain how to access TOS with Flutter SDK.​
Prerequisites​
Steps​
  1. Set up long-term access credentials locally.​
tip​
To obtain the access key ID and secret access key, see Access Key Management​
  • ​
    macOS
    Linux
    Windows
    ​
    Follow these steps to configure long-term access credentials on macOS.​
    1. Open Terminal and run this command to open the file.​
    • ​
      nano ~/.bash_profile​
      ​
    1. Add your access key ID and secret access key at the end of the file.​
    • ​
      export TOS_ACCESS_KEY=AKTPYmI1Z****​
      export TOS_SECRET_KEY=T1dJM01UU****​
      ​
    1. Save the file and exit.​
    1. Run this command to apply the configuration.​
    • ​
      source ~/.bash_profile​
      ​
    1. Run this command to verify the configuration.​
    • ​
      echo $TOS_ACCESS_KEY​
      echo $TOS_SECRET_KEY​
      ​
    • The following output confirms a successful configuration.​
    • ​
      AKTPYmI1Z****​
      T1dJM01UU****​
      ​
    ​
  1. Run this command to install the TOS Flutter SDK.​
tip​
For more information on the TOS Flutter SDK, see tos package.​
  • ​
    flutter pub add tos​
    ​
  1. Access TOS with Flutter SDK.​
  • Replace region and endpoint with the actual region and endpoint in the code below, and then run it.​
tip​
When setting the endpoint parameter, add https:// before the domain name. For example: https://tos-cn-beijing.volces.com. For more information on endpoints, see Regions and endpoints.​
​
import 'dart:io' show Platform;​
import 'package:tos/enum.dart';​
import 'package:tos/exception.dart';​
import 'package:tos/tos.dart';​
​
void main() async {​
Map<String, String> envVars = Platform.environment;​
TosClient client = TosClientBuilder()​
.ak(envVars['TOS_ACCESS_KEY'] ?? '')​
.sk(envVars['TOS_SECRET_KEY'] ?? '')​
.region('cn-beijing')​
.endpoint('https://tos-cn-beijing.volces.com')​
.build();​
​
var output = await client.listBuckets(ListBucketsInput());​
print(output.requestId);​
for(var bucket in output.buckets){​
print(bucket.name);​
}​
client.close();​
}​
​
A returned bucket name confirms a successful access operation.​
Related operations​
You can consult the API documentation to write your own code for tasks such as creating buckets and deleting objects. For more API documentation on the TOS Flutter SDK, see tos library.​
Last updated: 2026.10.12 14:16:23