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博客")

相关推荐
sweet丶7 小时前
流程图解:Asset Catalog 的完整生命周期
ios
yyuuuzz16 小时前
aws注册过程中的常见注意事项
云计算·aws
空中海2 天前
iOS 动态分析、抓包与 Frida Hook
ios·职场和发展·蓝桥杯
yyuuuzz2 天前
aws 基础认知与实践注意点
运维·服务器·网络·云计算·github·aws
亚马逊云开发者2 天前
Aurora PG 14 快 EOL 了,我用蓝绿部署 52 秒切到了 PG 16,聊聊全过程
aws
亚马逊云开发者2 天前
证书 47 天就过期,还在手动续?聊聊我在 AWS 上的自动化方案
aws
空中海2 天前
iOS 静态逆向、IPA 结构与 Mach-O 分析
ios·华为·harmonyos
Mr -老鬼2 天前
EasyClick 双端自动化智能体|Android&iOS 全平台 EC 脚本开发助手
android·ios·自动化·易点云测·#easyclick·#ios自动化
空中海2 天前
01. iOS 逆向基础、环境搭建与授权
macos·ios·cocoa
空中海2 天前
iOS LLDB 调试、Mach-O、Runtime 与二进制分析
macos·ios·cocoa