AWS SDK在iOS中的简单使用

//配置信息

AWSBasicSessionCredentialsProvider *provider = \[AWSBasicSessionCredentialsProvider allocinitWithAccessKey:accessKeyId secretKey:accessKeySecret sessionToken:securityToken];

AWSEndpoint *endpoint = \[AWSEndpoint allocinitWithRegion:AWSRegionUnknown service:AWSServiceS3 URL:bucketURL];

AWSServiceConfiguration *configuration = \[AWSServiceConfiguration allocinitWithRegion:AWSRegionUSEast2 endpoint:endpoint credentialsProvider:provider];

\[AWSServiceManager defaultServiceManagersetDefaultServiceConfiguration:configuration];

AWSS3 *s3 = AWSS3 defaultS3;

//请求信息

AWSS3PutObjectRequest *putRequest = \[AWSS3PutObjectRequest allocinit];

putRequest.bucket = bucket;

putRequest.key = key;

//获取文件的大小

NSDictionary *fileAttributes = \[NSFileManager defaultManagerattributesOfItemAtPath: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博客

相关推荐
老李IT笔记10 小时前
关掉设备上的 AI 扩展:两个键各管一层,配错了等于没配
人工智能·ios·智能手机
2501_9159214311 小时前
iOS应用耗电测试:使用Energy Log、Keymob和Instruments进行性能监控与能源消耗分析
android·ios·小程序·https·uni-app·iphone·webview
黑化旺仔13 小时前
RunLoop 源码探索
ios·cocoa·xcode
茶底世界之下16 小时前
叶片纹理要多硬?用 Awaking 只加一点清晰度
ios
无风听海18 小时前
AWS CLI的profile
云计算·aws
2501_9151063218 小时前
KXApp 的 VS Code 真机调试:按下 Cmd+R 之后发生了什么
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
ii_best19 小时前
安卓手机开发、iOS 手机开发都能用:按键精灵远程调试,设备在千里外也能改脚本
android·ios·智能手机·自动化·按键精灵
翼龙云_cloud1 天前
亚马逊云服务器服务代理商:Bedrock 实践经验 Serverless 架构下的 AI 自动化落地
服务器·架构·serverless·云计算·aws
开心猴爷1 天前
应对iOS审核4.3:可以使用 IpaGuard 来给属性名混淆的技术细节与平衡之道
后端·ios
iOS开发上架哦1 天前
iOS应用耗电测试:使用Energy Log、Keymob和Instruments进行性能监控与能源消耗分析
后端·ios