You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

尝试复制文件至已存在Wasabi桶时抛出NoSuchBucketException

问题诊断与解决方案

核心问题

你的S3AsyncClient配置中,仅当endpoint包含localhost时才会设置endpointOverride和路径风格访问,但Wasabi的生产环境endpoint并不包含localhost,导致SDK默认使用AWS S3的服务地址发送请求,自然无法找到你在Wasabi上创建的桶。

修复步骤

1. 修改S3AsyncClient配置

移除对localhost的判断,强制配置Wasabi的endpoint和路径风格访问(Wasabi要求使用路径风格访问,而非虚拟主机风格):

@Bean(name = "wasabiS3Async")
public S3AsyncClient wasabiS3Async(@Qualifier("wasabiCredentialsProvider") AwsCredentialsProvider awsCredentialsProvider,
                                   @Value("${the.region}") String region,
                                   @Value("${the.endpoint}") String endpoint) throws URISyntaxException {
    SdkAsyncHttpClient nettyHttpClient = NettyNioAsyncHttpClient.builder()
            .connectionAcquisitionTimeout(Duration.ofHours(3))
            .connectionTimeout(Duration.ofHours(3))
            .readTimeout(Duration.ofHours(3))
            .writeTimeout(Duration.ofHours(3))
            .maxConcurrency(100)
            .build();
    return S3AsyncClient.builder()
            .credentialsProvider(awsCredentialsProvider)
            .region(Region.of(region))
            .httpClient(nettyHttpClient)
            .endpointOverride(new URI(endpoint))
            .serviceConfiguration(S3Configuration.builder()
                    .pathStyleAccessEnabled(true) // Wasabi要求路径风格访问
                    .build())
            .build();
}

2. 验证配置参数正确性

  • Endpoint:确认${the.endpoint}配置的是Wasabi的正确地址,比如:
    • 通用地址:https://s3.wasabisys.com
    • 区域特定地址:https://s3.us-east-1.wasabisys.com(需和桶所在区域匹配)
  • Region:确保配置的区域与你在Wasabi控制台创建桶时选择的区域完全一致(比如us-east-1、eu-central-1等)
  • Credentials:再次确认Access Key和Secret Key拥有该桶的读取/写入权限

3. 可选:添加桶存在性验证(调试用)

可以在复制方法前添加一段代码,验证客户端能否正常访问桶,帮助排查权限或配置问题:

// 在copyFile方法开头添加
try {
    wasabiS3TransferManager.s3Client().headBucket(HeadBucketRequest.builder().bucket(bucketName).build()).join();
    log.info("桶 {} 存在且可访问", bucketName);
} catch (S3Exception e) {
    log.error("桶访问失败", e);
}

额外注意事项

  • Wasabi的API兼容S3,但部分细节(如endpoint规则、访问风格)与AWS S3有差异,必须严格按照Wasabi文档配置客户端
  • 避免在生产环境设置过长的超时时间(你当前设置的3小时),建议根据实际业务调整为合理值

内容的提问来源于stack exchange,提问作者Space Cadet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 01:37:27