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

相关推荐
亚马逊云开发者3 小时前
更新个监控 Agent 要协调 200 个团队?Amazon ECS 托管守护进程终于把平台工程师从苦海里捞出来了
aws
Mr_CrazyPeter8 小时前
iONSPlayer 1.1.1版本发布
游戏·ios·模拟器
亚马逊云开发者10 小时前
5 个 Agent 协同处理金融业务,我用 Kiro + AgentCore 半天就部署上线了
aws
秋雨梧桐叶落莳10 小时前
iOS——UI入门
ui·ios·cocoa
zhensherlock11 小时前
Protocol Launcher 系列:Agenda 优雅组织你的想法与日程
javascript·macos·ios·typescript·node.js·mac·ipad
Rhys..11 小时前
webdriveragent setup教程
ios
亚马逊云开发者13 小时前
我把 Claude Code 的 Token 费砍了 70%,只用了 SageMaker + 一个路由 Hook
aws
报错小能手14 小时前
ios开发方向——swift内存基础
开发语言·ios·swift
SY.ZHOU14 小时前
移动端架构体系(二):本地持久化与动态部署
flutter·ios·安卓
圣殿骑士-Khtangc15 小时前
Amazon CodeWhisperer 超详细使用教程:AWS 云原生 AI 编程助手上手指南
人工智能·ai编程·aws·编程助手·codewhisperer