Skip to content

Commit ea1c0bd

Browse files
authored
Merge pull request #6 from cnblogs/v0.3.2
Refacotry BucketInfo.CreateByRegion
2 parents 2692567 + b17dd8b commit ea1c0bd

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/Cuiliang.AliyunOssSdk.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<PackageTags>Aliyun</PackageTags>
77
<Authors>Cuiliang</Authors>
88
<PackageProjectUrl>https://github.com/cnblogs/Cuiliang.AliyunOssSdk</PackageProjectUrl>
9+
<IsPackable>true</IsPackable>
910
</PropertyGroup>
1011
<ItemGroup>
1112
<Folder Include="Properties\" />

src/Entites/BucketInfo.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,27 @@ public static BucketInfo CreateByCname(Uri uri, string bucket)
6969
/// <returns></returns>
7070
public static BucketInfo CreateByRegion(string region, string bucketName, bool useHttps = false, bool useInternal = false)
7171
{
72-
var baseDomain = useInternal? "-internal.aliyuncs.com" : ".aliyuncs.com";
73-
var method = useHttps ? "https://" : "http://";
72+
var uriBuilder = new UriBuilder();
73+
uriBuilder.Scheme = useHttps ? "https" : "http";
74+
uriBuilder.Host = region + (useInternal ? "-internal.aliyuncs.com" : ".aliyuncs.com");
7475

7576
var bucket = new BucketInfo()
7677
{
7778
IsCname = false,
7879
BucketName = bucketName,
79-
IsHttps = useHttps
80+
IsHttps = useHttps,
81+
EndpointUri = uriBuilder.Uri
8082
};
8183

82-
bucket.EndpointUri = new Uri(method + region + baseDomain);
83-
84-
// bucket名称为空的情况,直接访问oss
85-
bucket.BucketUri = String.IsNullOrEmpty(bucketName)? bucket.EndpointUri : new Uri(method + bucketName + "." + region + baseDomain);
84+
if(string.IsNullOrEmpty(bucketName))
85+
{
86+
bucket.BucketUri = bucket.EndpointUri;
87+
}
88+
else
89+
{
90+
uriBuilder.Host = bucketName + "." + uriBuilder.Host;
91+
bucket.BucketUri = uriBuilder.Uri;
92+
}
8693

8794
return bucket;
8895
}

tests/Sample/Sample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
55
</PropertyGroup>
6-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
6+
<PropertyGroup>
77
<LangVersion>latest</LangVersion>
88
</PropertyGroup>
99
<ItemGroup>

0 commit comments

Comments
 (0)