BucketViewController.m
11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//
// BucketViewController.m
// KS3iOSSDKDemo
//
// Created by Blues on 12/16/14.
// Copyright (c) 2014 Blues. All rights reserved.
//
#warning Please set correct bucket name
#define kBucketName @"acc"
//#define kBucketName @"alert1"
#import "BucketViewController.h"
#import <KS3YunSDK.h>
#import "KS3Util.h"
#import <CNLiveUploadSDK/CNLiveUpload.h>
@interface BucketViewController ()
@property (nonatomic, strong) NSArray *arrItems;
@end
@implementation BucketViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Bucket";
_arrItems = [NSArray arrayWithObjects:
@"Create Bucket", @"Delete Bucket", @"Head Bucket",
@"Get Bucket ACL", @"Set Bucket ACL", @"Set Bucket Grant ACL",
@"Get Bucket Logging", @"Set Bucket Logging",
@"Get All Objects In Bucket", nil];
}
#pragma mark - UITableView datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _arrItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *strIdentifier = @"bucket identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIdentifier];
if (nil == cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strIdentifier];
}
cell.textLabel.text = _arrItems[indexPath.row];
return cell;
}
#pragma mark - UITableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *strIdentifier = @"";
switch (indexPath.row) {
case 0:
{
strIdentifier = @"Create Bucket Identifier";
[self performSegueWithIdentifier:strIdentifier sender:nil];
}
break;
case 1:
{
KS3DeleteBucketRequest *deleteBucketReq = [[KS3DeleteBucketRequest alloc] initWithName:@"1222"];
[deleteBucketReq setCompleteRequest];
NSArray *array = [deleteBucketReq.kSYHeader componentsSeparatedByString:@"\n"];
NSString *headers = [array firstObject];
[CNLiveUpload getAuthDicWithMd5:deleteBucketReq.contentMd5 verb:deleteBucketReq.httpMethod type:deleteBucketReq.contentType res:deleteBucketReq.kSYResource headers:headers date:deleteBucketReq.strDate success:^(NSDictionary *dic) {
//使用token签名时从Appserver获取token后设置token,使用Ak sk则忽略,不需要调用
[deleteBucketReq setStrKS3Token:dic[@"Authorization"]];
KS3DeleteBucketResponse *response = [[KS3Client initialize] deleteBucket:deleteBucketReq];
if (response.httpStatusCode == 204) { // **** 没有返回任何内容
NSLog(@"Delete bucket success!");
}
else {
NSLog(@"Delete bucket error: %@", response.error.description);
}
} failure:^(NSDictionary *error) {
NSLog(@"error %@",error);
}];
}
break;
case 2:
{
KS3HeadBucketRequest *headBucketReq = [[KS3HeadBucketRequest alloc] initWithName:kBucketName];
[headBucketReq setCompleteRequest];
NSArray *array = [headBucketReq.kSYHeader componentsSeparatedByString:@"\n"];
NSString *headers = [array firstObject];
[CNLiveUpload getAuthDicWithMd5:headBucketReq.contentMd5 verb:headBucketReq.httpMethod type:headBucketReq.contentType res:headBucketReq.kSYResource headers:headers date:headBucketReq.strDate success:^(NSDictionary *dic) {
//使用token签名时从Appserver获取token后设置token,使用Ak sk则忽略,不需要调用
[headBucketReq setStrKS3Token:dic[@"Authorization"]];
KS3HeadBucketResponse *responsee = [[KS3Client initialize] headBucket:headBucketReq];
if (responsee.httpStatusCode == 200) {
NSLog(@"Head bucket success");
}
else {
NSLog(@"Head bucket error: %@", responsee.error.description);
}
}failure:^(NSDictionary *error) {
NSLog(@"error %@",error);
}];
}
break;
case 3:
{
KS3GetACLRequest *getBucketAclReq = [[KS3GetACLRequest alloc] initWithName:@"bjtest"];
[getBucketAclReq setCompleteRequest];
NSArray *array = [getBucketAclReq.kSYHeader componentsSeparatedByString:@"\n"];
NSString *headers = [array firstObject];
[CNLiveUpload getAuthDicWithMd5:getBucketAclReq.contentMd5 verb:getBucketAclReq.httpMethod type:getBucketAclReq.contentType res:getBucketAclReq.kSYResource headers:headers date:getBucketAclReq.strDate success:^(NSDictionary *dic) {
//使用token签名时从Appserver获取token后设置token,使用Ak sk则忽略,不需要调用
[getBucketAclReq setStrKS3Token:dic[@"Authorization"]];
KS3GetACLResponse *response = [[KS3Client initialize] getBucketACL:getBucketAclReq];
KS3BucketACLResult *result = response.listBucketsResult;
if (response.httpStatusCode == 200) {
NSLog(@"Get bucket acl success!");
NSLog(@"Bucket owner ID: %@",result.owner.ID);
NSLog(@"Bucket owner displayName: %@",result.owner.displayName);
for (KS3Grant *grant in result.accessControlList) {
NSLog(@"%@",grant.grantee.ID);
NSLog(@"%@",grant.grantee.displayName);
NSLog(@"%@",grant.grantee.URI);
NSLog(@"_______________________");
NSLog(@"%@",grant.permission);
}
}
else {
NSLog(@"Get bucket acl error: %@", response.error.description);
}
}failure:^(NSDictionary *error) {
NSLog(@"error %@",error);
}];
}
break;
case 4:
{
KS3AccessControlList *acl = [[KS3AccessControlList alloc] init];
[acl setContronAccess:KingSoftYun_Permission_Public_Read];
// setBucketACLReq.acl = acl;
KS3SetACLRequest *setBucketACLReq = [[KS3SetACLRequest alloc] initWithName:kBucketName accessACL:acl];
[setBucketACLReq setCompleteRequest];
NSArray *array = [setBucketACLReq.kSYHeader componentsSeparatedByString:@"\n"];
NSString *headers = [array firstObject];
[CNLiveUpload getAuthDicWithMd5:setBucketACLReq.contentMd5 verb:setBucketACLReq.httpMethod type:setBucketACLReq.contentType res:setBucketACLReq.kSYResource headers:headers date:setBucketACLReq.strDate success:^(NSDictionary *dic) {
//使用token签名时从Appserver获取token后设置token,使用Ak sk则忽略,不需要调用
[setBucketACLReq setStrKS3Token:dic[@"Authorization"]];
KS3SetACLResponse *response = [[KS3Client initialize] setBucketACL:setBucketACLReq];
NSLog(@"%@",[[NSString alloc] initWithData:response.body encoding:NSUTF8StringEncoding]);
if (response.httpStatusCode == 200) {
NSLog(@"Set bucket acl success!");
}
else {
NSLog(@"Set bucket acl error: %@", response.error.description);
}
}failure:^(NSDictionary *error) {
NSLog(@"error %@",error);
}];
}
break;
case 5:
{
KS3GrantAccessControlList *acl = [[KS3GrantAccessControlList alloc] init];
acl.identifier = @"4567894346";
acl.displayName = @"accDisplayName";
[acl setGrantControlAccess:KingSoftYun_Grant_Permission_Read];
KS3SetGrantACLRequest *setGrantACLRequest = [[KS3SetGrantACLRequest alloc] initWithName:kBucketName accessACL:acl];
[setGrantACLRequest setCompleteRequest];
NSArray *array = [setGrantACLRequest.kSYHeader componentsSeparatedByString:@"\n"];
NSString *headers = [array firstObject];
[CNLiveUpload getAuthDicWithMd5:setGrantACLRequest.contentMd5 verb:setGrantACLRequest.httpMethod type:setGrantACLRequest.contentType res:setGrantACLRequest.kSYResource headers:headers date:setGrantACLRequest.strDate success:^(NSDictionary *dic) {
//使用token签名时从Appserver获取token后设置token,使用Ak sk则忽略,不需要调用
[setGrantACLRequest setStrKS3Token:dic[@"Authorization"]];
KS3SetGrantACLResponse *response = [[KS3Client initialize] setGrantACL:setGrantACLRequest];
if (response.httpStatusCode == 200) {
NSLog(@"Set bucket grant acl success!");
}
else {
NSLog(@"Set bucket grant acl error: %@", response.error.description);
}
}failure:^(NSDictionary *error) {
NSLog(@"error %@",error);
}];
}
break;
case 6:
{
KS3GetBucketLoggingRequest *getBucketLoggingReq = [[KS3GetBucketLoggingRequest alloc] initWithName:kBucketName];
[getBucketLoggingReq setCompleteRequest];
NSArray *array = [getBucketLoggingReq.kSYHeader componentsSeparatedByString:@"\n"];
NSString *headers = [array firstObject];
[CNLiveUpload getAuthDicWithMd5:getBucketLoggingReq.contentMd5 verb:getBucketLoggingReq.httpMethod type:getBucketLoggingReq.contentType res:getBucketLoggingReq.kSYResource headers:headers date:getBucketLoggingReq.strDate success:^(NSDictionary *dic) {
//使用token签名时从Appserver获取token后设置token,使用Ak sk则忽略,不需要调用
[getBucketLoggingReq setStrKS3Token:dic[@"Authorization"]];
KS3GetBucketLoggingResponse *response = [[KS3Client initialize] getBucketLogging:getBucketLoggingReq];
if (response.httpStatusCode == 200) {
NSLog(@"Get bucket logging success!");
}
else {
NSLog(@"Get bucket logging error: %@", response.error.description);
}
}failure:^(NSDictionary *error) {
NSLog(@"error %@",error);
}];
}
break;
case 7:
{
NSLog(@"移动端暂不支持");
}
break;
case 8:
strIdentifier = @"Get All Objects In Bucket Identifier";
[self performSegueWithIdentifier:strIdentifier sender:nil];
break;
default:
break;
}
}
@end