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

相关推荐
1024小神4 小时前
关于在ios系统中签名并安装ipa文件的五种方法,PakePlus打包的ipa文件可以看看
macos·ios·cocoa
QWQ___qwq7 小时前
SwiftUI 的状态管理包装器(Property Wrapper)
ios·swiftui·swift
游戏开发爱好者810 小时前
苹果iOS26系统升级:液态玻璃与智能功能全解析
macos·ios·小程序·uni-app·objective-c·cocoa·iphone
心随雨下12 小时前
Flutter中新手需要掌握的几种Widget
android·flutter·ios
2501_9159184117 小时前
iOS 26 App 性能测试|性能评测|iOS 26 性能对比:实战策略
android·macos·ios·小程序·uni-app·cocoa·iphone
namehu1 天前
React Native 应用性能分析与优化不完全指南
android·react native·ios
王道长服务器 | 亚马逊云1 天前
AWS Shield 与海外高防服务器的对比分析
服务器·云计算·aws
weixin_307779131 天前
AWS云上ClickHouse数据仓库部署方案详解
开发语言·clickhouse·自动化·云计算·aws
Amy_au1 天前
AWS Lambda 学习笔
学习·云计算·aws
潇凝子潇1 天前
AWS CLI自动删除资源脚本
chrome·云计算·aws