需要用的类
#import <AWSS3.h>
#import <AWSCore.h>
//1和2需要在aws控制台里面配置
1.权限配置:访问控制列表 必须公有
2.存储桶策略
需要在编辑器加以下代码
//"Resource": "arn:aws:s3:::@“存储桶的名称”/*"
//其他固定
{
"Version": "2012-10-17",}
3. 在配置桶的时候 有一个js文件,需要倒入应用项目里面去,不然就闪退。
4.app里面的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//aws-视频上传配置
//桶的id PoolId:存储桶的PoolId(比如:us-west-2:xxxx-xxxx-xxxxx-xxxx)
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:@"存储桶的PoolId"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionEUWest2 credentialsProvider:credentialsProvider];
// AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
}
//5需要在上传功能里面写的代码
-(void)goto_aws_vop:(NSString*)url_im{
NSLog(@"开始");
NSURL* url=[NSURL URLWithString:_load_vo_url];//视频的url
AWSS3TransferUtilityUploadExpression* expression=[[AWSS3TransferUtilityUploadExpression alloc]init];
expression.progressBlock = ^(AWSS3TransferUtilityTask * _Nonnull task, NSProgress * _Nonnull progress) {
NSLog(@"expression==上传进度");
NSLog(@"上传进度=%f",progress.fractionCompleted);
};
AWSS3TransferUtility* transferUtility=[AWSS3TransferUtility defaultS3TransferUtility];
NSDateFormatter* formater = [[NSDateFormatter alloc] init];
[formater setDateFormat:@"yyyyMMddHHmmss"];
NSString* keyfileName = [NSString stringWithFormat:@"s3iosFolder/-%@.mp4",[formater stringFromDate:[NSDate date]]];
//s3iosFolder/ 在桶里面创建文件夹的名称
//text/plain tet文件
//video/mp4 视频
//bucket js里面文件的值bucket(比如:ios项目名称-userfiles-mobilehub-xxxxxxx)
[[transferUtility uploadFile:url bucket:@"js里面文件的值bucket" key:keyfileName contentType:@"video/mp4" expression:expression completionHandler:^(AWSS3TransferUtilityUploadTask * _Nonnull task, NSError * _Nullable error) {
NSLog(@"uploadFile");
NSLog(@"%@",error);
NSLog(@"%@",task.request);
if(error)
{
}else{
//成功之后:视频的url地址 在aws控制台是固定的
_aws_mp4_url=[NSString stringWithFormat:@"https://s3-us-west-2.amazonaws.com/bucket js里面文件的值bucket(比如:ios项目名称-userfiles-mobilehub-xxxxxxx)%@",keyfileName]; //上传成功的视频url
}
}] continueWithBlock:^id _Nullable(AWSTask<AWSS3TransferUtilityUploadTask *> * _Nonnull t) {
NSLog(@"%@",t.result);
NSLog(@"回调");
if (t.error) {
NSLog(@"Error: %@", t.error);
}
return nil;
}];
}