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

相关推荐
zhongben123_16 小时前
从零开发一个打车APP:技术选型、系统架构与成本评估指南
大数据·运维·ios·系统架构·uni-app·web app
茶底世界之下16 小时前
人像清晰度加多少?用 Awaking 对照皮肤与发丝
ios
Anhty19 小时前
2026三款AI变声器测评:iOS男变女自然声线实测
人工智能·功能测试·ios·智能手机
传奇开心果编程19 小时前
组合优先开发范式:从汉字造字原理到声明式UI组件组合思想
android·flutter·ios·swiftui·移动开发·harmonyos·android jetpack
腾讯端服务20 小时前
一码Duo端-Kuikly-iOS折叠屏新UI适配实践
android·ui·ios·kotlin·鸿蒙
2501_9159184120 小时前
Windows 上开发 React Native iOS,真机调试、Fast Refresh 与打包 ipa
windows·vscode·react native·ios·个人开发·swift·敏捷流程
aiopencode1 天前
局域网设备抓包怎么做?用 TraceEagle 抓电视、游戏机和 IoT 流量
后端·ios
奇牙coding1 天前
GPT-5.5 报 401 invalid_api_key 怎么办?换密钥前按 4 层排查请求头、项目权限和端点
数据库·gpt·ios·ai
szp20051 天前
中文字幕烧进视频后整片空白:CoreText 低报行高,导出照样成功
ios·swift
二流小码农1 天前
HarmonyOS开发助手,0代码让元服务从开发到上架
android·ios·harmonyos