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

相关推荐
G佳伟43 分钟前
如何解决解决,微信小程序ios无法长按复制问题<text>设置 selectable=“true“不起作用
ios·微信小程序·小程序
Nick56831 小时前
Apple Pay 与 Google Pay 开发与结算全流程文档
ios·安卓·android-studio
全栈派森1 小时前
初见 Dart:这门新语言如何让你的 App「动」起来?
android·flutter·ios
HarderCoder1 小时前
Swift 内存管理:吃透 ARC 、weak、unowned
ios·swift
Digitally2 小时前
5种将照片从iPhone传输到戴尔PC/笔记本电脑的方法
ios·电脑·iphone
月屯2 小时前
平台消息推送(go)
数据库·后端·golang·cocoa·iphone·gin
ajassi20002 小时前
开源 Objective-C IOS 应用开发(三)第一个iPhone的APP
ios·开源·objective-c
Daniel_Coder8 小时前
iOS Widget 开发-9:可配置 Widget:使用 IntentConfiguration 实现参数选择
ios·swiftui·swift·widget·intents
非专业程序员Ping11 小时前
Vibe Coding 实战!花了两天时间,让 AI 写了一个富文本渲染引擎!
ios·ai·swift·claude·vibecoding
00后程序员张13 小时前
HTTP抓包工具推荐,Fiddler配置方法、代理设置与使用教程详解(开发者必学网络调试技巧)
网络·http·ios·小程序·fiddler·uni-app·webview