iOS中使用AWS上传zip文件到Minio上的oss平台上
1. 集成AWS相关库(万万不要用最新的版本,否则会出现风格化虚拟路径,找不到主机名)pod 'AWSS3', '~> 2.10.0'
pod 'AWSCore', '~> 2.10.0' 2. 编写集成的相关代码
- (void)uploadFileToMinIO {
NSString *endPoint = @"http://192.168.1.31:9000"; // 有的需要加端口,有的不需要
NSString *accessKey = @"FDX7fP3XbXXCvwbAQfefUzOiGf"; //minio后台申请的
NSString *secretKey = @"QrtJww9vcEy383126ZRX4LxxSNo2iC03yy5lbnJQnTcA"; //minio后台申请的
NSString *bucketName = @"桶名"; // 从minio后台创建
AWSEndpoint *endpoint = [ initWithRegion:AWSRegionUSEast1
service:AWSServiceS3
URL:];
NSLog(@"czf007: requestURL: %@", endpoint.URL.absoluteString);
AWSStaticCredentialsProvider *credentialsProvider =
[ initWithAccessKey:accessKey
secretKey:secretKey];
AWSServiceConfiguration *configuration =
[ initWithRegion:AWSRegionUSEast1
endpoint:endpoint
credentialsProvider:credentialsProvider];
// .defaultServiceConfiguration = configuration; // 这个不能设置,会导致走虚拟化路径,使用下面的方式即可
;
AWSS3PutObjectRequest *putRequest = ;
putRequest.bucket = bucketName;
putRequest.key = @"yourfile.zip";
putRequest.body = ;
putRequest.contentType = @"application/zip";
// 设置 contentLength,防止 ExcessData 错误
NSDictionary *attrs = [ attributesOfItemAtPath:@"/work/redsocks.zip" error:nil];
NSNumber *fileSizeNumber = ;
putRequest.contentLength = fileSizeNumber;
NSLog(@"czf007: uploading file with size: %@", fileSizeNumber);
[ putObject:putRequest
completionHandler:^(AWSS3PutObjectOutput * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"czf007:upload failed: %@", error);
} else {
NSLog(@"czf007:upload success!");
}
}];
} 3. 查看日志
https://i-blog.csdnimg.cn/direct/96681562fbd54a80a0965ebfcfc63206.png
4. 在Minio后台查看文件是否上传成功
https://i-blog.csdnimg.cn/direct/a87de0b4bda24440a65a7f7b6fdf5bc7.png
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]