分片上传接口 融合接口 SDK提供封装好的融合接口,方便用户实现分片上传的功能。 接口定义 plaintext (AWSTask )uploadData:(NSData )data key:(NSString )key contentType:(NSString )contentType expression:(nullable AWSS3TransferUtilityUploadExpression )expression completionHandler:(nullable AWSS3TransferUtilityUploadCompletionHandlerBlock)completionHandler; (AWSTask )uploadData:(NSData )data bucket:(NSString )bucket key:(NSString )key contentType:(NSString )contentType expression:(nullable AWSS3TransferUtilityUploadExpression )expression completionHandler:(nullable AWSS3TransferUtilityUploadCompletionHandlerBlock)completionHandler; 参数说明 参数名 类型 说明 bucket NSString bucket名 key NSString 要上传的对象名称 data NSData 文件内容 contentType NSString 文件类型 expression AWSS3TransferUtilityUploadExpression 其他参数,设置progress回调,设置acl completionHandler AWSS3TransferUtilityUploadCompletionHandlerBlock 上传文件结果回调 代码示例 plaintext (IBAction)start:(id)sender { weak UploadViewController weakSelf self; NSString fileName @"test40M.mp4"; NSString path [[NSBundle mainBundle] pathForResource:fileName ofType:nil]; NSData fileData [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:nil]; AWSS3TransferUtilityUploadExpression expression [AWSS3TransferUtilityUploadExpression new]; //设置公共读 //[expression setValue:@"publicread" forRequestHeader:@"xamzacl"]; expression.progressBlock ^(AWSS3TransferUtilityTask Nonnull task, NSProgress Nonnull progress) { dispatchasync(dispatchgetmainqueue(), ^{ weakSelf.progressView.progress progress.fractionCompleted; }); }; AWSS3TransferUtilityUploadCompletionHandlerBlock completionHandler ^(AWSS3TransferUtilityUploadTask task, NSError error) { dispatchasync(dispatchgetmainqueue(), ^{ if(error) { weakSelf.statusLabel.text @"Failed to Upload"; } else { weakSelf.statusLabel.text @"Successfully Uploaded"; } }); }; AWSS3TransferUtility transferUtility [AWSS3TransferUtility defaultS3TransferUtility]; [[transferUtility uploadData:fileData bucket:self.mBucketName key:fileName contentType:@"video/mp4" expression:expression completionHandler:completionHandler] continueWithBlock:^id(AWSTask task) { if (task.error) { NSLog(@"Error: %@", task.error); return nil; } if (task.result) { NSLog(@"Upload Starting!"); } return nil; }]; } 标准接口 标准接口由以下接口组合完成分片上传文件的功能:createMultipartUpload,uploadPart,completeMultipartUpload,abortMultipartUpload。