halo设置附件上传时选择南京地区的问题

jdysya
jdysya

在区域列表中并没有南京的选项,若我们填入中文的南京,从日志中可以看到,对应的basePath中竟然夹杂着中文”南京“

Pasted image 20220826140822

2022-08-26 11:08:46.399  INFO 5000 --- [qtp478182173-122] r.h.app.handler.file.FilePathDescriptor  : FilePathDescriptor: [FilePathDescriptor(name=截屏2022-07-31 21.38.18, extension=png, relativePath=截屏2022-07-31 21.38.18.png, basePath=https://xxx.cos.南京.myqcloud.com, fullName=截屏2022-07-31 21.38.18.png, fullPath=https://xxx.cos.南京.myqcloud.com/截屏2022-07-31 21.38.18.png, subPath=)]
2022-08-26 11:08:46.410 ERROR 5000 --- [qtp478182173-122] r.h.app.core.ControllerExceptionHandler  : Captured an exception:

run.halo.app.exception.FileOperationException: 附件 截屏2022-07-31 21.38.18.png 上传失败(腾讯云)

...
...
...

Caused by: java.lang.IllegalArgumentException: region name only should contain lowercase characters, num, . and -
	at com.qcloud.cos.internal.UrlComponentUtils.validateComponent(UrlComponentUtils.java:51) ~[cos_api-5.6.61.jar!/:na]
	at com.qcloud.cos.internal.UrlComponentUtils.validateRegionName(UrlComponentUtils.java:57) ~[cos_api-5.6.61.jar!/:na]
	at com.qcloud.cos.region.Region.formatRegion(Region.java:65) ~[cos_api-5.6.61.jar!/:na]
	at com.qcloud.cos.region.Region.formatRegion(Region.java:61) ~[cos_api-5.6.61.jar!/:na]
	at com.qcloud.cos.endpoint.RegionEndpointBuilder.buildGeneralApiEndpoint(RegionEndpointBuilder.java:38) ~[cos_api-5.6.61.jar!/:na]
	at com.qcloud.cos.COSClient.buildUrlAndHost(COSClient.java:516) ~[cos_api-5.6.61.jar!/:na]
	at com.qcloud.cos.COSClient.createRequest(COSClient.java:264) ~[cos_api-5.6.61.jar!/:na]
	at com.qcloud.cos.COSClient.uploadObjectInternal(COSClient.java:846) ~[cos_api-5.6.61.jar!/:na]
	at com.qcloud.cos.COSClient.putObject(COSClient.java:775) ~[cos_api-5.6.61.jar!/:na]
	at com.qcloud.cos.COSClient.putObject(COSClient.java:991) ~[cos_api-5.6.61.jar!/:na]
	at run.halo.app.handler.file.TencentCosFileHandler.upload(TencentCosFileHandler.java:110) ~[classes!/:1.5.4]
	... 114 common frames omitted

从后面的报错信息Caused by: java.lang.IllegalArgumentException: region name only should contain lowercase characters, num, . and -来看,更加能证明前面的观点

回到腾讯云cos的控制台,我们发现实际上访问域名中,南京对应的是ap-nanjing

将halo附件上传界面的区域改为ap-nanjing后则可以正常上传附件