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_9160074713 小时前
前端开发常用软件与工具全面指南
android·ios·小程序·https·uni-app·iphone·webview
sweet丶17 小时前
iOS AI 编程环境配置:Agent、Skill、Rules、Hook、Command
ios·ai编程
专注VB编程开发20年17 小时前
swift,object-c同名函数重载
macos·objective-c·cocoa
2501_9159090617 小时前
iOS应用性能优化:十大策略提升用户体验与开发效率
android·ios·小程序·https·uni-app·iphone·webview
白玉cfc21 小时前
【iOS】底层原理:分类、扩展和关联对象
ios·分类·数据挖掘
2601_955767421 天前
观复盾护景贴:东方哲思与双护科技的深度实测
人工智能·科技·ios·iphone·圆偏振光·磁控溅射
会Tk矩阵群控的小木1 天前
企业级iMessage群发系统实战:单主机管控多iPhone设备完整实现
运维·ios·开源软件·个人开发
人月神话-Lee1 天前
【图像处理】vImage/Accelerate——SIMD 让 CPU 也能飞
图像处理·深度学习·ios·cnn·ai编程·swift
万能小林子1 天前
如何将网页在线转APP?5种打包工具对比速成指南(含在线/手机/电脑方案)
android·ios·uni-app·web app·wap2app·app打包·app封装
2601_955767421 天前
iPhone 17屏幕反光怎么解?磁控溅射AR膜实测反射率低至0.5%
ios·ar·iphone·#观复盾护景贴·scinique双护技术