AWS SDK在iOS中的简单使用

//配置信息

AWSBasicSessionCredentialsProvider *provider = [[AWSBasicSessionCredentialsProvider alloc]initWithAccessKey:accessKeyId secretKey:accessKeySecret sessionToken:securityToken];

AWSEndpoint *endpoint = [[AWSEndpoint alloc]initWithRegion:AWSRegionUnknown service:AWSServiceS3 URL:bucketURL];

AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc]initWithRegion:AWSRegionUSEast2 endpoint:endpoint credentialsProvider:provider];

\[AWSServiceManager defaultServiceManager\]setDefaultServiceConfiguration:configuration\]; AWSS3 \*s3 = \[AWSS3 defaultS3\]; //请求信息 AWSS3PutObjectRequest \*putRequest = \[\[AWSS3PutObjectRequest alloc\]init\]; putRequest.bucket = bucket; putRequest.key = key; //获取文件的大小 NSDictionary \*fileAttributes = \[\[NSFileManager defaultManager\]attributesOfItemAtPath:videoUrl.path error:**nil**\]; **if** (fileAttributes) { NSNumber \*fileSize = \[fileAttributes objectForKey:NSFileSize\]; //要上传内容的大小 putRequest.contentLength = fileSize; } //上传的内容,可以是data也可以是URL putRequest.body = videoUrl; **if**(\[type isEqualToString:@"1"\]){//视频 putRequest.contentType = @"video/mp4"; putRequest.body = videoUrl; }**else** **if** (\[type isEqualToString:@"0"\]){//图片 putRequest.contentType = @"image/jpeg"; NSData \*dataBody = UIImageJPEGRepresentation(image, 0.5); putRequest.body = dataBody; putRequest.contentLength = \[NSNumber numberWithLong:dataBody.length\]; } putRequest.uploadProgress = \^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) { // totalBytes: data.length 数据的总长度 // totalBytesSent: 已完成的长度 }; \[s3 putObject:putRequest completionHandler:\^(AWSS3PutObjectOutput \* **_Nullable** response, NSError \* **_Nullable** error) { **if** (error) { }**else**{ } }\]; 参考文章:[AWSS3 iOS SDK使用教程_aws s3 sdk-CSDN博客](https://blog.csdn.net/leleyuan1130/article/details/128715069 "AWSS3 iOS SDK使用教程_aws s3 sdk-CSDN博客")

相关推荐
可观测性用观测云2 小时前
AWS EKS 集群日志上报观测云实践
aws
liucan2333 小时前
JS执行速度似乎并不比Swift或者C语言慢
前端·ios
安和昂5 小时前
【iOS】 Block再学习
学习·ios·cocoa
pop_xiaoli5 小时前
OC学习—命名规范
学习·ios
亚林瓜子8 小时前
AWS Elastic Beanstalk + CodePipeline(Python Flask Web的国区CI/CD)
python·ci/cd·flask·web·aws·beanstalk·codepipeline
过河不拆乔8 小时前
AWS 公开数据集下载与操作说明
学习·云计算·aws
阿山同学.9 小时前
AWS 亚马逊 S3存储桶直传 前端demo 复制即可使用
前端·javascript·aws
AWS官方合作商9 小时前
Amazon RDS on AWS Outposts:解锁本地化云数据库的混合云新体验
云原生·云计算·aws
Digitally9 小时前
如何在没有 iTunes 的情况下备份 iPhone
ios·iphone
刘_小_二10 小时前
iOS用Xib 之三等分以及多等分思路
ios