Skip to content

Commit

Permalink
Merge pull request #6 from cnblogs/v0.3.2
Browse files Browse the repository at this point in the history
Refacotry BucketInfo.CreateByRegion
  • Loading branch information
cnblogs-dudu authored Jan 12, 2019
2 parents 2692567 + b17dd8b commit ea1c0bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Cuiliang.AliyunOssSdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<PackageTags>Aliyun</PackageTags>
<Authors>Cuiliang</Authors>
<PackageProjectUrl>https://github.com/cnblogs/Cuiliang.AliyunOssSdk</PackageProjectUrl>
<IsPackable>true</IsPackable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Properties\" />
Expand Down
21 changes: 14 additions & 7 deletions src/Entites/BucketInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,27 @@ public static BucketInfo CreateByCname(Uri uri, string bucket)
/// <returns></returns>
public static BucketInfo CreateByRegion(string region, string bucketName, bool useHttps = false, bool useInternal = false)
{
var baseDomain = useInternal? "-internal.aliyuncs.com" : ".aliyuncs.com";
var method = useHttps ? "https://" : "http://";
var uriBuilder = new UriBuilder();
uriBuilder.Scheme = useHttps ? "https" : "http";
uriBuilder.Host = region + (useInternal ? "-internal.aliyuncs.com" : ".aliyuncs.com");

var bucket = new BucketInfo()
{
IsCname = false,
BucketName = bucketName,
IsHttps = useHttps
IsHttps = useHttps,
EndpointUri = uriBuilder.Uri
};

bucket.EndpointUri = new Uri(method + region + baseDomain);

// bucket名称为空的情况,直接访问oss
bucket.BucketUri = String.IsNullOrEmpty(bucketName)? bucket.EndpointUri : new Uri(method + bucketName + "." + region + baseDomain);
if(string.IsNullOrEmpty(bucketName))
{
bucket.BucketUri = bucket.EndpointUri;
}
else
{
uriBuilder.Host = bucketName + "." + uriBuilder.Host;
bucket.BucketUri = uriBuilder.Uri;
}

return bucket;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
Expand Down

0 comments on commit ea1c0bd

Please sign in to comment.