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

相关推荐
茶底世界之下9 小时前
灯塔照片怎么裁竖幅?用 Awaking 留住塔顶,收紧两侧环境
ios
庚鑫13 小时前
iOS 27 兼容放大模式下,keyboardFrame 与 UIScreen.bounds 的坐标差异
ios·objective-c
HEJOO914 小时前
iOS 高效绘图:从 Core Graphics 到 Metal 的实践指南
macos·ios·cocoa
HEJOO914 小时前
iOS 性能优化全面详解
ios·性能优化·cocoa
ii_best14 小时前
iOS 自动化脚本工具更新|按键精灵 适配 Relaxin(青霉素)越狱,兼容 iOS16~iOS26 主流越狱环境
ios·自动化·按键精灵
万年咸鱼14 小时前
iOS 27 适配笔记
笔记·ios·cocoa
可达智灵14 小时前
堵了门,钥匙还在:一次持续九个月的 AWS 接管修复
云计算·aws·可达智灵
云边云科技_云网融合15 小时前
混合云组网难题破解:SD-WAN 如何打通 AWS 与阿里云,让总部分支访问稳如专线
阿里云·云计算·aws
HEJOO915 小时前
iOS Dark Mode 适配笔记
笔记·ios·cocoa
风雨_17 小时前
Mac M3 使用 OrbStack 全新安装运行 EasyConnect 完整教程
ios