Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refacotry BucketInfo.CreateByRegion #6

Merged
merged 3 commits into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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