Commit 3bf2be226545caff26158904a26cca895ee295da
1 parent
a49b6bed
移除BucketName
Showing
5 changed files
with
147 additions
and
146 deletions
CNLiveUploadYunSDKDemo/CNLiveUploadYunSDKDemo.xcodeproj/project.pbxproj
| ... | ... | @@ -17,6 +17,7 @@ |
| 17 | 17 | 81B9CBA81F54207B009594FB /* KS3YunSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81B9CBA31F54205E009594FB /* KS3YunSDK.framework */; }; |
| 18 | 18 | 81B9CBA91F54207B009594FB /* KS3YunSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 81B9CBA31F54205E009594FB /* KS3YunSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; |
| 19 | 19 | 81B9CBAE1F5421C6009594FB /* 7.6M.mov in Resources */ = {isa = PBXBuildFile; fileRef = 81B9CBAD1F5421C6009594FB /* 7.6M.mov */; }; |
| 20 | + D21D75D51FE0C9C700658839 /* cnlive.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = D21D75D41FE0C9C600658839 /* cnlive.mp4 */; }; | |
| 20 | 21 | D2DD1B311FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2DD1B301FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework */; }; |
| 21 | 22 | D2DD1B331FDFDA6F001DFDD1 /* CNLiveUploadYunSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D2DD1B301FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; |
| 22 | 23 | /* End PBXBuildFile section */ |
| ... | ... | @@ -51,6 +52,7 @@ |
| 51 | 52 | 81B9CBA01F54204F009594FB /* CNLiveUploadController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLiveUploadController.m; sourceTree = "<group>"; }; |
| 52 | 53 | 81B9CBA31F54205E009594FB /* KS3YunSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = KS3YunSDK.framework; sourceTree = "<group>"; }; |
| 53 | 54 | 81B9CBAD1F5421C6009594FB /* 7.6M.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = 7.6M.mov; sourceTree = "<group>"; }; |
| 55 | + D21D75D41FE0C9C600658839 /* cnlive.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = cnlive.mp4; sourceTree = "<group>"; }; | |
| 54 | 56 | D2DD1B301FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = CNLiveUploadYunSDK.framework; sourceTree = "<group>"; }; |
| 55 | 57 | /* End PBXFileReference section */ |
| 56 | 58 | |
| ... | ... | @@ -95,6 +97,7 @@ |
| 95 | 97 | 81B9CB9F1F54204F009594FB /* CNLiveUploadController.h */, |
| 96 | 98 | 81B9CBA01F54204F009594FB /* CNLiveUploadController.m */, |
| 97 | 99 | 81B9CBAD1F5421C6009594FB /* 7.6M.mov */, |
| 100 | + D21D75D41FE0C9C600658839 /* cnlive.mp4 */, | |
| 98 | 101 | 81B9CB911F542006009594FB /* Main.storyboard */, |
| 99 | 102 | 81B9CB941F542006009594FB /* Assets.xcassets */, |
| 100 | 103 | 81B9CB961F542006009594FB /* LaunchScreen.storyboard */, |
| ... | ... | @@ -173,6 +176,7 @@ |
| 173 | 176 | buildActionMask = 2147483647; |
| 174 | 177 | files = ( |
| 175 | 178 | 81B9CBAE1F5421C6009594FB /* 7.6M.mov in Resources */, |
| 179 | + D21D75D51FE0C9C700658839 /* cnlive.mp4 in Resources */, | |
| 176 | 180 | 81B9CB981F542006009594FB /* LaunchScreen.storyboard in Resources */, |
| 177 | 181 | 81B9CB951F542006009594FB /* Assets.xcassets in Resources */, |
| 178 | 182 | 81B9CB931F542006009594FB /* Main.storyboard in Resources */, | ... | ... |
CNLiveUploadYunSDKDemo/CNLiveUploadYunSDKDemo/AppDelegate.h
CNLiveUploadYunSDKDemo/CNLiveUploadYunSDKDemo/AppDelegate.m
| ... | ... | @@ -25,7 +25,9 @@ |
| 25 | 25 | self.window.rootViewController = nav; |
| 26 | 26 | [self.window makeKeyAndVisible]; |
| 27 | 27 | |
| 28 | + //设置地区 | |
| 28 | 29 | [[CNLiveClient initialize] setBucketDomainWithRegion:CNLiveBucketBeijing]; |
| 30 | + //初始化云上传SDK | |
| 29 | 31 | [CNLiveUpload setAppId:AppId appKey:AppKey isTestEnvironment:NO]; |
| 30 | 32 | |
| 31 | 33 | return YES; | ... | ... |
CNLiveUploadYunSDKDemo/CNLiveUploadYunSDKDemo/CNLiveUploadController.m
| ... | ... | @@ -21,19 +21,18 @@ |
| 21 | 21 | |
| 22 | 22 | @interface CNLiveUploadController ()<UITableViewDelegate,UITableViewDataSource,KingSoftServiceRequestDelegate> |
| 23 | 23 | { |
| 24 | - NSString *_bucketName;//SP对应的bucketName | |
| 25 | 24 | NSString *_bucketKey;//SP上传时用到的bucket里文件的路径(包含扩展名) |
| 26 | 25 | } |
| 27 | -@property (nonatomic ,strong) UITableView * tableView; | |
| 26 | +@property (nonatomic ,strong) UITableView * tableView;//列表 | |
| 28 | 27 | |
| 29 | -@property (assign, nonatomic) long long fileSize; | |
| 30 | -@property (assign, nonatomic) NSInteger partSize; | |
| 31 | -@property (assign, nonatomic) long long partLength; | |
| 32 | -@property (nonatomic) NSInteger uploadNum; | |
| 33 | -@property (nonatomic) NSInteger totalNum; | |
| 34 | -@property (strong, nonatomic) NSFileHandle *fileHandle; | |
| 35 | -@property (nonatomic, strong) NSArray *arrItems; | |
| 36 | -@property (strong, nonatomic) CNLiveMultipartUpload *muilt; | |
| 28 | +@property (assign, nonatomic) long long fileSize;//文件大小 | |
| 29 | +@property (assign, nonatomic) NSInteger partSize;//单块大小 | |
| 30 | +@property (assign, nonatomic) long long partLength;//单块长度 | |
| 31 | +@property (nonatomic) NSInteger uploadNum;//当前上传块 | |
| 32 | +@property (nonatomic) NSInteger totalNum;//上传总块数 | |
| 33 | +@property (strong, nonatomic) NSFileHandle *fileHandle;//文件管理 | |
| 34 | +@property (nonatomic, strong) NSArray *arrItems;//数据源 | |
| 35 | +@property (strong, nonatomic) CNLiveMultipartUpload *muilt;//分块上传对象 | |
| 37 | 36 | @end |
| 38 | 37 | |
| 39 | 38 | @implementation CNLiveUploadController |
| ... | ... | @@ -51,16 +50,18 @@ |
| 51 | 50 | self.tableView.delegate = self; |
| 52 | 51 | self.tableView.dataSource = self; |
| 53 | 52 | |
| 54 | - _bucketName = [CNLiveUpload getSPBucketName]; | |
| 55 | - NSLog(@"bucketName:%@",_bucketName); | |
| 56 | 53 | [self getBucketKeyFromServer]; |
| 57 | 54 | } |
| 58 | 55 | |
| 56 | + | |
| 57 | +/** | |
| 58 | + 从服务器获取BucketKey,BucketKey为文件路径 | |
| 59 | + */ | |
| 59 | 60 | - (void)getBucketKeyFromServer |
| 60 | 61 | { |
| 61 | 62 | #warning 此处建议从server获取 上传文件对应的bucketKey(文件路径包含扩展名) |
| 62 | 63 | #warning Demo为了演示 bucketKey用固定值 |
| 63 | - _bucketKey = @"cnlive122/test123-7.6M.mov"; | |
| 64 | + _bucketKey = @"cnlive-test/cnlive.mp4"; | |
| 64 | 65 | } |
| 65 | 66 | |
| 66 | 67 | #pragma mark 相册方法 |
| ... | ... | @@ -135,108 +136,104 @@ |
| 135 | 136 | */ |
| 136 | 137 | - (void)beginMultipartUpload |
| 137 | 138 | { |
| 138 | - if(_bucketName == nil){ | |
| 139 | - _bucketName = [CNLiveUpload getSPBucketName]; | |
| 140 | - if (!_bucketName) { | |
| 141 | - NSLog(@"获取BucketName失败,请检查视讯云上传模块权限是否配置!"); | |
| 142 | - return; | |
| 143 | - } | |
| 144 | - } | |
| 145 | - | |
| 146 | - NSString *strKey = _bucketKey; | |
| 147 | - _partSize = 5; // 文件大于5M为最小5M一块 | |
| 148 | - | |
| 149 | - CNLiveAccessControlList *acl = [[CNLiveAccessControlList alloc] init]; | |
| 150 | - [acl setContronAccess:CNLiveYun_Permission_Public_Read]; | |
| 151 | - | |
| 152 | - CNLiveInitiateMultipartUploadRequest *initMultipartUploadReq = [[CNLiveInitiateMultipartUploadRequest alloc] initWithKey:strKey inBucket:_bucketName acl:acl grantAcl:nil]; | |
| 153 | - [initMultipartUploadReq setCompleteRequest]; | |
| 154 | - | |
| 155 | - NSArray *array = [initMultipartUploadReq.CNYHeader componentsSeparatedByString:@"\n"]; | |
| 156 | - NSString *headers = [array firstObject]; | |
| 157 | - | |
| 158 | - [CNLiveUpload getTokenWithMd5:initMultipartUploadReq.contentMd5 verb:initMultipartUploadReq.httpMethod type:initMultipartUploadReq.contentType res:initMultipartUploadReq.CNYResource headers:headers date:initMultipartUploadReq.strDate success:^(NSString *token ,NSString *cnliveDate) { | |
| 159 | - [initMultipartUploadReq setStrCNLiveToken:token]; | |
| 160 | - [initMultipartUploadReq setStrDate:cnliveDate]; | |
| 161 | - _muilt = [[CNLiveClient initialize] initiateMultipartUploadWithRequest:initMultipartUploadReq]; | |
| 139 | + [CNLiveUpload initCNLiveUploadWithSuccess:^{ | |
| 140 | + NSString *strKey = _bucketKey; | |
| 141 | + _partSize = 5; // 文件大于5M为最小5M一块 | |
| 162 | 142 | |
| 163 | - if (_muilt == nil) { | |
| 164 | - NSLog(@"####Init upload failed, please check access key, secret key and bucket name!####"); | |
| 165 | - return ; | |
| 166 | - } | |
| 143 | + CNLiveAccessControlList *acl = [[CNLiveAccessControlList alloc] init]; | |
| 144 | + [acl setContronAccess:CNLiveYun_Permission_Public_Read]; | |
| 167 | 145 | |
| 168 | - //选择相册还是普通方式 | |
| 169 | - _muilt.uploadType = kCNLiveUploadNormal; | |
| 146 | + CNLiveInitiateMultipartUploadRequest *initMultipartUploadReq = [[CNLiveInitiateMultipartUploadRequest alloc] initWithKey:strKey acl:acl grantAcl:nil]; | |
| 147 | + [initMultipartUploadReq setCompleteRequest]; | |
| 170 | 148 | |
| 171 | - //根据文件路径不一样,有如下两种上传 | |
| 172 | - if (_muilt.uploadType == kCNLiveUploadNormal) { //如果是沙盒或者工程里的文件 | |
| 173 | - //工程里,沙盒里,是沙盒路径 | |
| 174 | - NSString *strFilePath = [[NSBundle mainBundle] pathForResource:@"7.6M" ofType:@"mov"]; | |
| 175 | - _fileHandle = [NSFileHandle fileHandleForReadingAtPath:strFilePath]; | |
| 176 | - _fileSize = [_fileHandle availableData].length; | |
| 177 | - if (_fileSize <= 0) { | |
| 178 | - NSLog(@"####This file is not exist!####"); | |
| 179 | - return ; | |
| 180 | - } | |
| 181 | - if (!(_partSize > 0 || _partSize != 0)) { | |
| 182 | - _partLength = _fileSize; | |
| 183 | - }else{ | |
| 184 | - _partLength = _partSize * 1024.0 * 1024.0; | |
| 185 | - } | |
| 186 | - _totalNum = (ceilf((float)_fileSize / (float)_partLength)); | |
| 187 | - [_fileHandle seekToFileOffset:0]; | |
| 188 | - }else | |
| 189 | - { | |
| 190 | - //如果是相册里的,从这传 | |
| 191 | - ALAssetRepresentation *assetD = [self getAlasset].defaultRepresentation; | |
| 192 | - _fileSize = assetD.size; | |
| 193 | - if (_fileSize <= 0) { | |
| 194 | - NSLog(@"####This file is not exist!####"); | |
| 149 | + NSArray *array = [initMultipartUploadReq.CNYHeader componentsSeparatedByString:@"\n"]; | |
| 150 | + NSString *headers = [array firstObject]; | |
| 151 | + | |
| 152 | + [CNLiveUpload getTokenWithMd5:initMultipartUploadReq.contentMd5 verb:initMultipartUploadReq.httpMethod type:initMultipartUploadReq.contentType res:initMultipartUploadReq.CNYResource headers:headers date:initMultipartUploadReq.strDate success:^(NSString *token ,NSString *cnliveDate) { | |
| 153 | + [initMultipartUploadReq setStrCNLiveToken:token]; | |
| 154 | + [initMultipartUploadReq setStrDate:cnliveDate]; | |
| 155 | + _muilt = [[CNLiveClient initialize] initiateMultipartUploadWithRequest:initMultipartUploadReq]; | |
| 156 | + | |
| 157 | + if (_muilt == nil) { | |
| 158 | + NSLog(@"####Init upload failed, please check access key, secret key and bucket name!####"); | |
| 195 | 159 | return ; |
| 196 | 160 | } |
| 197 | - if (!(_partSize > 0 || _partSize != 0)) { | |
| 198 | - _partLength = _fileSize; | |
| 199 | - }else{ | |
| 200 | - _partLength = _partSize * 1024.0 * 1024.0; | |
| 161 | + | |
| 162 | + //选择相册还是普通方式 | |
| 163 | + _muilt.uploadType = kCNLiveUploadNormal; | |
| 164 | + | |
| 165 | + //根据文件路径不一样,有如下两种上传 | |
| 166 | + if (_muilt.uploadType == kCNLiveUploadNormal) { //如果是沙盒或者工程里的文件 | |
| 167 | + //工程里,沙盒里,是沙盒路径 | |
| 168 | + NSString *strFilePath = [[NSBundle mainBundle] pathForResource:@"7.6M" ofType:@"mov"]; | |
| 169 | + _fileHandle = [NSFileHandle fileHandleForReadingAtPath:strFilePath]; | |
| 170 | + _fileSize = [_fileHandle availableData].length; | |
| 171 | + if (_fileSize <= 0) { | |
| 172 | + NSLog(@"####This file is not exist!####"); | |
| 173 | + return ; | |
| 174 | + } | |
| 175 | + if (!(_partSize > 0 || _partSize != 0)) { | |
| 176 | + _partLength = _fileSize; | |
| 177 | + }else{ | |
| 178 | + _partLength = _partSize * 1024.0 * 1024.0; | |
| 179 | + } | |
| 180 | + _totalNum = (ceilf((float)_fileSize / (float)_partLength)); | |
| 181 | + [_fileHandle seekToFileOffset:0]; | |
| 182 | + }else | |
| 183 | + { | |
| 184 | + //如果是相册里的,从这传 | |
| 185 | + ALAssetRepresentation *assetD = [self getAlasset].defaultRepresentation; | |
| 186 | + _fileSize = assetD.size; | |
| 187 | + if (_fileSize <= 0) { | |
| 188 | + NSLog(@"####This file is not exist!####"); | |
| 189 | + return ; | |
| 190 | + } | |
| 191 | + if (!(_partSize > 0 || _partSize != 0)) { | |
| 192 | + _partLength = _fileSize; | |
| 193 | + }else{ | |
| 194 | + _partLength = _partSize * 1024.0 * 1024.0; | |
| 195 | + } | |
| 196 | + _totalNum = (ceilf((float)_fileSize / (float)_partLength)); | |
| 201 | 197 | } |
| 202 | - _totalNum = (ceilf((float)_fileSize / (float)_partLength)); | |
| 203 | - } | |
| 204 | - | |
| 198 | + | |
| 205 | 199 | #warning 上传的断点续传判断:初始化上传后,开始上传前,此处需要list一下所有的数据块,如果uploadID是新生成的,可以跳过list过程从第一块开始传,如果上传是断点续传,需用初始化用到的uploadId,list一下所有已经传过的数据块,再从暂停块上传即可, 这里用NSUserDefault演示存储过程。 |
| 206 | - //判断uploadId是否存在,进而进行上传的断点续传 | |
| 207 | - if ([mUserDefaults objectForKey:keyUploadId] == nil) { | |
| 208 | - [mUserDefaults setObject:_muilt.uploadId forKey:keyUploadId]; | |
| 209 | - [mUserDefaults synchronize]; | |
| 210 | - _uploadNum = 1; | |
| 211 | - [self uploadWithPartNumber:_uploadNum]; | |
| 212 | - }else | |
| 213 | - { | |
| 214 | - _muilt.uploadId = [mUserDefaults objectForKey:keyUploadId]; | |
| 215 | - //list一下所有上传过的块 | |
| 216 | - CNLiveListPartsRequest *req2 = [[CNLiveListPartsRequest alloc] initWithMultipartUpload:_muilt]; | |
| 217 | - [req2 setCompleteRequest]; | |
| 218 | - [CNLiveUpload getTokenWithMd5:req2.contentMd5 verb:req2.httpMethod type:req2.contentType res:req2.CNYResource headers:headers date:req2.strDate success:^(NSString *token ,NSString *cnliveDate) { | |
| 219 | - [req2 setStrCNLiveToken:token]; | |
| 220 | - [req2 setStrDate:cnliveDate]; | |
| 221 | - CNLiveListPartsResponse *response2 = [[CNLiveClient initialize] listParts:req2]; | |
| 222 | - | |
| 223 | - NSLog(@"response.listResult.parts.count =%lu",(unsigned long)[response2.listResult.parts count]); | |
| 224 | - | |
| 225 | - //从这块开始上传,list结果的最后一块 | |
| 226 | - _uploadNum = ((CNLivePart *)[response2.listResult.parts lastObject]).partNumber + 1 ; | |
| 227 | - | |
| 228 | - //进度补齐 | |
| 229 | - long long alreadyTotalWriten = (_uploadNum - 1) * _partLength ; | |
| 230 | - double progress = alreadyTotalWriten / (float)_fileSize; | |
| 231 | - UIProgressView *progressView = (UIProgressView *)[self.view viewWithTag:199]; | |
| 232 | - progressView.progress = progress; | |
| 200 | + //判断uploadId是否存在,进而进行上传的断点续传 | |
| 201 | + if ([mUserDefaults objectForKey:keyUploadId] == nil) { | |
| 202 | + [mUserDefaults setObject:_muilt.uploadId forKey:keyUploadId]; | |
| 203 | + [mUserDefaults synchronize]; | |
| 204 | + _uploadNum = 1; | |
| 233 | 205 | [self uploadWithPartNumber:_uploadNum]; |
| 234 | - } failure:^(NSDictionary *error) { | |
| 235 | - | |
| 236 | - }]; | |
| 237 | - } | |
| 206 | + }else | |
| 207 | + { | |
| 208 | + _muilt.uploadId = [mUserDefaults objectForKey:keyUploadId]; | |
| 209 | + //list一下所有上传过的块 | |
| 210 | + CNLiveListPartsRequest *req2 = [[CNLiveListPartsRequest alloc] initWithMultipartUpload:_muilt]; | |
| 211 | + [req2 setCompleteRequest]; | |
| 212 | + [CNLiveUpload getTokenWithMd5:req2.contentMd5 verb:req2.httpMethod type:req2.contentType res:req2.CNYResource headers:headers date:req2.strDate success:^(NSString *token ,NSString *cnliveDate) { | |
| 213 | + [req2 setStrCNLiveToken:token]; | |
| 214 | + [req2 setStrDate:cnliveDate]; | |
| 215 | + CNLiveListPartsResponse *response2 = [[CNLiveClient initialize] listParts:req2]; | |
| 216 | + | |
| 217 | + NSLog(@"response.listResult.parts.count =%lu",(unsigned long)[response2.listResult.parts count]); | |
| 218 | + | |
| 219 | + //从这块开始上传,list结果的最后一块 | |
| 220 | + _uploadNum = ((CNLivePart *)[response2.listResult.parts lastObject]).partNumber + 1 ; | |
| 221 | + | |
| 222 | + //进度补齐 | |
| 223 | + long long alreadyTotalWriten = (_uploadNum - 1) * _partLength ; | |
| 224 | + double progress = alreadyTotalWriten / (float)_fileSize; | |
| 225 | + UIProgressView *progressView = (UIProgressView *)[self.view viewWithTag:199]; | |
| 226 | + progressView.progress = progress; | |
| 227 | + [self uploadWithPartNumber:_uploadNum]; | |
| 228 | + } failure:^(NSDictionary *error) { | |
| 229 | + NSLog(@"error %@",error); | |
| 230 | + }]; | |
| 231 | + } | |
| 232 | + } failure:^(NSDictionary *error) { | |
| 233 | + NSLog(@"error %@",error); | |
| 234 | + }]; | |
| 238 | 235 | } failure:^(NSDictionary *error) { |
| 239 | - | |
| 236 | + NSLog(@"error %@",error); | |
| 240 | 237 | }]; |
| 241 | 238 | } |
| 242 | 239 | |
| ... | ... | @@ -313,7 +310,7 @@ |
| 313 | 310 | NSLog(@"error: %@", response.error.description); |
| 314 | 311 | } |
| 315 | 312 | } failure:^(NSDictionary *error) { |
| 316 | - | |
| 313 | + NSLog(@"error %@",error); | |
| 317 | 314 | }]; |
| 318 | 315 | } |
| 319 | 316 | |
| ... | ... | @@ -321,46 +318,43 @@ |
| 321 | 318 | //最小支持但块上传小于5M,最大支持单块上传为5G |
| 322 | 319 | - (void)beginSingleUpload:(NSInteger) row |
| 323 | 320 | { |
| 324 | - if(_bucketName == nil){ | |
| 325 | - _bucketName = [CNLiveUpload getSPBucketName]; | |
| 326 | - if (!_bucketName) { | |
| 327 | - NSLog(@"获取BucketName失败,请检查视讯云上传模块权限是否配置!"); | |
| 328 | - return; | |
| 329 | - } | |
| 330 | - } | |
| 331 | - CNLiveAccessControlList *ControlList = [[CNLiveAccessControlList alloc] init]; | |
| 332 | - [ControlList setContronAccess:CNLiveYun_Permission_Public_Read_Write]; | |
| 333 | - CNLivePutObjectRequest *putObjRequest = [[CNLivePutObjectRequest alloc] initWithName:_bucketName withAcl:ControlList grantAcl:nil]; | |
| 334 | - NSString *fileName = [[NSBundle mainBundle] pathForResource:@"7.6M" ofType:@"mov"]; | |
| 335 | - putObjRequest.data = [NSData dataWithContentsOfFile:fileName options:NSDataReadingMappedIfSafe error:nil]; | |
| 336 | - _fileSize = putObjRequest.data.length; | |
| 337 | - | |
| 338 | - putObjRequest.delegate = self; | |
| 339 | - putObjRequest.filename = _bucketKey; | |
| 340 | - putObjRequest.contentMd5 = [CNLiveSDKUtil base64md5FromData:putObjRequest.data]; | |
| 341 | - [putObjRequest setCompleteRequest]; | |
| 342 | - | |
| 343 | - NSArray *array = [putObjRequest.CNYHeader componentsSeparatedByString:@"\n"]; | |
| 344 | - NSString *headers = [array firstObject]; | |
| 345 | - | |
| 346 | - [CNLiveUpload getTokenWithMd5:putObjRequest.contentMd5 verb:putObjRequest.httpMethod type:putObjRequest.contentType res:putObjRequest.CNYResource headers:headers date:putObjRequest.strDate success:^(NSString *token ,NSString *cnliveDate) { | |
| 347 | - [putObjRequest setStrCNLiveToken:token]; | |
| 348 | - [putObjRequest setStrDate:cnliveDate]; | |
| 349 | - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
| 350 | - CNLivePutObjectResponse *response = [[CNLiveClient initialize] putObject:putObjRequest]; | |
| 351 | - | |
| 352 | - //putObjRequest若没设置代理,则是同步的下方判断, | |
| 353 | - //putObjRequest若设置了代理,则走上传代理回调, | |
| 354 | - if (putObjRequest.delegate == nil) { | |
| 355 | - NSLog(@"%@",[[NSString alloc] initWithData:response.body encoding:NSUTF8StringEncoding]); | |
| 356 | - if (response.httpStatusCode == 200) { | |
| 357 | - NSLog(@"Put object success"); | |
| 358 | - } | |
| 359 | - else { | |
| 360 | - NSLog(@"Put object failed"); | |
| 321 | + [CNLiveUpload initCNLiveUploadWithSuccess:^{ | |
| 322 | + CNLiveAccessControlList *ControlList = [[CNLiveAccessControlList alloc] init]; | |
| 323 | + [ControlList setContronAccess:CNLiveYun_Permission_Public_Read_Write]; | |
| 324 | + CNLivePutObjectRequest *putObjRequest = [[CNLivePutObjectRequest alloc] initWithAcl:ControlList grantAcl:nil]; | |
| 325 | + NSString *fileName = [[NSBundle mainBundle] pathForResource:@"7.6M" ofType:@"mov"]; | |
| 326 | + putObjRequest.data = [NSData dataWithContentsOfFile:fileName options:NSDataReadingMappedIfSafe error:nil]; | |
| 327 | + _fileSize = putObjRequest.data.length; | |
| 328 | + | |
| 329 | + putObjRequest.delegate = self; | |
| 330 | + putObjRequest.filename = _bucketKey; | |
| 331 | + putObjRequest.contentMd5 = [CNLiveSDKUtil base64md5FromData:putObjRequest.data]; | |
| 332 | + [putObjRequest setCompleteRequest]; | |
| 333 | + | |
| 334 | + NSArray *array = [putObjRequest.CNYHeader componentsSeparatedByString:@"\n"]; | |
| 335 | + NSString *headers = [array firstObject]; | |
| 336 | + | |
| 337 | + [CNLiveUpload getTokenWithMd5:putObjRequest.contentMd5 verb:putObjRequest.httpMethod type:putObjRequest.contentType res:putObjRequest.CNYResource headers:headers date:putObjRequest.strDate success:^(NSString *token ,NSString *cnliveDate) { | |
| 338 | + [putObjRequest setStrCNLiveToken:token]; | |
| 339 | + [putObjRequest setStrDate:cnliveDate]; | |
| 340 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
| 341 | + CNLivePutObjectResponse *response = [[CNLiveClient initialize] putObject:putObjRequest]; | |
| 342 | + | |
| 343 | + //putObjRequest若没设置代理,则是同步的下方判断, | |
| 344 | + //putObjRequest若设置了代理,则走上传代理回调, | |
| 345 | + if (putObjRequest.delegate == nil) { | |
| 346 | + NSLog(@"%@",[[NSString alloc] initWithData:response.body encoding:NSUTF8StringEncoding]); | |
| 347 | + if (response.httpStatusCode == 200) { | |
| 348 | + NSLog(@"Put object success"); | |
| 349 | + } | |
| 350 | + else { | |
| 351 | + NSLog(@"Put object failed"); | |
| 352 | + } | |
| 361 | 353 | } |
| 362 | - } | |
| 363 | - }); | |
| 354 | + }); | |
| 355 | + } failure:^(NSDictionary *error) { | |
| 356 | + NSLog(@"error %@",error); | |
| 357 | + }]; | |
| 364 | 358 | } failure:^(NSDictionary *error) { |
| 365 | 359 | NSLog(@"error %@",error); |
| 366 | 360 | }]; | ... | ... |
CNLiveUploadYunSDKDemo/CNLiveUploadYunSDKDemo/cnlive.mp4
0 → 100644
No preview for this file type