2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
+ using System . Net . Http ;
5
6
using System . Threading . Tasks ;
6
7
using Cuiliang . AliyunOssSdk . Api ;
7
8
using Cuiliang . AliyunOssSdk . Api . Bucket . List ;
@@ -24,17 +25,13 @@ namespace Cuiliang.AliyunOssSdk
24
25
/// </summary>
25
26
public class OssClient
26
27
{
27
- private RequestContext _requestContext = null ;
28
+ private readonly HttpClient _client ;
29
+ private readonly RequestContext _requestContext ;
28
30
29
- public OssClient ( OssCredential credential )
30
- : this ( credential , ClientConfiguration . Default )
31
+ public OssClient ( HttpClient client , RequestContext requestContext )
31
32
{
32
-
33
- }
34
-
35
- public OssClient ( OssCredential credential , ClientConfiguration config )
36
- {
37
- _requestContext = new RequestContext ( credential , config ) ;
33
+ _client = client ;
34
+ _requestContext = requestContext ;
38
35
}
39
36
40
37
/// <summary>
@@ -44,7 +41,7 @@ public OssClient(OssCredential credential, ClientConfiguration config)
44
41
public async Task < OssResult < ListBucketsResult > > ListBucketsAsync ( string region )
45
42
{
46
43
var cmd = new ListBucketCommand ( _requestContext , region , new ListBucketsRequest ( ) ) ;
47
- return await cmd . ExecuteAsync ( ) ;
44
+ return await cmd . ExecuteAsync ( _client ) ;
48
45
}
49
46
50
47
/// <summary>
@@ -58,7 +55,7 @@ public async Task<OssResult<PutObjectResult>> PutObjectAsync(BucketInfo bucket,
58
55
{
59
56
var cmd = new PutObjectCommand ( _requestContext , bucket , key , file , null ) ;
60
57
61
- return await cmd . ExecuteAsync ( ) ;
58
+ return await cmd . ExecuteAsync ( _client ) ;
62
59
}
63
60
64
61
/// <summary>
@@ -113,14 +110,14 @@ public async Task<OssResult<PutObjectResult>> PutObjectByFileNameAsync(BucketInf
113
110
/// <param name="targetKey"></param>
114
111
/// <param name="extraHeaders"></param>
115
112
/// <returns></returns>
116
- public async Task < OssResult < CopyObjectResult > > CopyObjectAsync ( BucketInfo bucket , string srcKey ,
113
+ public async Task < OssResult < CopyObjectResult > > CopyObjectAsync ( BucketInfo bucket , string srcKey ,
117
114
BucketInfo targetBucket ,
118
- string targetKey ,
115
+ string targetKey ,
119
116
IDictionary < string , string > extraHeaders = null )
120
117
{
121
118
var cmd = new CopyObjectCommand ( _requestContext , targetBucket , targetKey , bucket , srcKey , extraHeaders ) ;
122
119
123
- return await cmd . ExecuteAsync ( ) ;
120
+ return await cmd . ExecuteAsync ( _client ) ;
124
121
}
125
122
126
123
/// <summary>
@@ -134,7 +131,7 @@ public async Task<OssResult<GetObjectResult>> GetObjectAsync(BucketInfo bucket,
134
131
{
135
132
var cmd = new GetObjectCommand ( _requestContext , bucket , key , parameters ) ;
136
133
137
- return await cmd . ExecuteAsync ( ) ;
134
+ return await cmd . ExecuteAsync ( _client ) ;
138
135
}
139
136
140
137
/// <summary>
@@ -150,7 +147,7 @@ public async Task<OssResult<AppentObjectResult>> AppendObject(BucketInfo bucket,
150
147
{
151
148
var cmd = new AppendObjectCommand ( _requestContext , bucket , key , nextAppendPosition , file ) ;
152
149
153
- return await cmd . ExecuteAsync ( ) ;
150
+ return await cmd . ExecuteAsync ( _client ) ;
154
151
}
155
152
156
153
/// <summary>
@@ -163,7 +160,7 @@ public async Task<OssResult<DeleteObjectResult>> DeleteObjectAsync(BucketInfo bu
163
160
{
164
161
var cmd = new DeleteObjectCommand ( _requestContext , bucket , key ) ;
165
162
166
- return await cmd . ExecuteAsync ( ) ;
163
+ return await cmd . ExecuteAsync ( _client ) ;
167
164
}
168
165
169
166
/// <summary>
@@ -178,7 +175,7 @@ public async Task<OssResult<DeleteMultipleObjectsResult>> DeleteMultipleObjectsA
178
175
{
179
176
var cmd = new DeleteMultipleObjectsCommand ( _requestContext , bucket , keys , quiet ) ;
180
177
181
- return await cmd . ExecuteAsync ( ) ;
178
+ return await cmd . ExecuteAsync ( _client ) ;
182
179
}
183
180
184
181
/// <summary>
@@ -191,7 +188,7 @@ public async Task<OssResult<DeleteMultipleObjectsResult>> DeleteMultipleObjectsA
191
188
public async Task < OssResult < HeadObjectResult > > HeadObjectAsync ( BucketInfo bucket , string key , HeadObjectParams parameters )
192
189
{
193
190
var cmd = new HeadObjectCommand ( _requestContext , bucket , key , parameters ) ;
194
- return await cmd . ExecuteAsync ( ) ;
191
+ return await cmd . ExecuteAsync ( _client ) ;
195
192
}
196
193
197
194
/// <summary>
@@ -203,7 +200,7 @@ public async Task<OssResult<HeadObjectResult>> HeadObjectAsync(BucketInfo bucket
203
200
public async Task < OssResult < GetObjectMetaResult > > GetObjectMetaAsync ( BucketInfo bucket , string key )
204
201
{
205
202
var cmd = new GetObjectMetaCommand ( _requestContext , bucket , key ) ;
206
- return await cmd . ExecuteAsync ( ) ;
203
+ return await cmd . ExecuteAsync ( _client ) ;
207
204
}
208
205
}
209
206
}
0 commit comments