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

相关推荐
2501_916008898 小时前
全平台抓包工具,Windows、iPhone、Linux三个平台抓包测试
网络协议·计算机网络·网络安全·ios·adb·https·udp
2501_9159184111 小时前
怎么把 Python 写的 Flet 应用打包成 iOS App 并上架 App Store?
android·ios·小程序·https·uni-app·iphone·webview
李游Leo13 小时前
HarmonyOS 7 实战开发 04:适配手机、折叠屏与大屏布局
ios·harmonyos
终端安全笔记13 小时前
iOS 27 强制 TLS 1.2:租赁设备的注册链路会在哪一环断
android·网络·安全·ios·智能手机
黑科技iOS上架13 小时前
iOS深度混淆flutter应用的最佳实践
flutter·ios·混淆·审核·深度混淆
思盛iOS签名上架14 小时前
IOS企业签名作用(核心作用一)
ios·testfight
黑科技iOS上架1 天前
unity3D 应用AppStore4.3被拒怎么自查
ios·审核·unity3d混淆
翼龙云_cloud1 天前
亚马逊云代理商:GPT-6 Astra 上线 Amazon Bedrock API 调用与企业集成实操
云计算·aws·gpt-6 astra
用户38034165882971 天前
FFmpeg 在 iOS 上的裁剪、集成与包体控制
ios·音视频开发
黑科技iOS上架1 天前
Cocos应用App Store4.3被拒怎么自查
macos·ios·objective-c·cocoa·审核·ios混淆·cocos混淆