tencent cloud

Cloud Object Storage

문서Cloud Object Storage

Set Custom DNS

포커스 모드
폰트 크기
마지막 업데이트 시간: 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);




도움말 및 지원

문제 해결에 도움이 되었나요?

피드백