tencent cloud

Cloud Object Storage

Set Custom DNS

Download
Focus Mode
Font Size
Last updated: 2025-07-01 10:07:06

Overview

This document provides how to use custom DNS to request the COS service.

Setting Dynamic Custom DNS Callback

This method is recommended because it is more flexible and easier to control at the business layer.

Example Code

// Configure after initializing the key
await Cos().initCustomerDNSFetch(FetchDns());

import 'package:flutter/foundation.dart';
import 'package:tencentcloud_cos_sdk_plugin/fetch_dns.dart';
// Implement the IFetchDns callback API
class FetchDns implements IFetchDns{
static Map<String, List<String>> dnsMap = {
'service.cos.myqcloud.com': ["106.119.174.56", "106.119.174.57", "106.119.174.55"],
'cos.ap-guangzhou.myqcloud.com': ["27.155.119.179", "27.155.119.180", "27.155.119.166", "27.155.119.181"],
};
@override
Future<List<String>?> fetchDns(String domain) async {
// Use endsWith to filter and match more subdomains, such as 000000-1253960454.cos.ap-guangzhou.myqcloud.com can also match cos.ap-guangzhou.myqcloud.com
final matchedEntries = dnsMap.entries.where((entry) => domain.endsWith(entry.key));
for (var entry in matchedEntries) {
if (kDebugMode) {
print('Host: ${entry.key}, IPS: ${entry.value}');
}
return entry.value;
}
return null;
}
}

Setting Static Custom DNS Configuration

The following code shows how to set static custom DNS configuration.

Example Code

Map<String, List<String>> dnsMap = {
'service.cos.myqcloud.com': ["106.119.174.56", "106.119.174.57", "106.119.174.55"],
'000000-1253960454.cos.ap-guangzhou.myqcloud.com': ["27.155.119.179", "27.155.119.180", "27.155.119.166", "27.155.119.181"],
'cos.ap-guangzhou.myqcloud.com': ["27.155.119.179", "27.155.119.180", "27.155.119.166", "27.155.119.181"],
};
// Configure after initializing the key
await Cos().initCustomerDNS(dnsMap);




Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback