To run the example project, clone the repo, and run pod install
from the Example directory first.
XMX_AliYunOSS is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'XMX_AliYunOSS' ,:git => 'https://github.com/736497373/XMX_AliYunOSS'
OSSCustomSignerCredentialProvider *credentialProviderByServer = [[DefaultOSSCredential sharedInstance] getOSSCredentialProviderByServerWithBlock:^(OSSFederationToken * _Nonnull token, dispatch_semaphore_t _Nonnull sem) {
// 在此处发送请求获取凭证信息设置token
token.tAccessKey = .accessKeyId;
token.tSecretKey = .accessKeySecret;
token.expirationTimeInGMTFormat = .expiration;
token.tToken = .securityToken;
// 设置完token后更新等待信号量
dispatch_semaphore_signal(sem);
}];
// 本地配置accessKey accessSecret
NSString *accessKey = @"";
NSString *accessSecret = @"";
NSError * error = [NSError errorWithDomain:@"www.xxxxxx.com" code:-1001 userInfo:nil];
OSSCustomSignerCredentialProvider *credentialProviderByOnwer = [[DefaultOSSCredential sharedInstance] getOSSCredentialProviderByOnwerWithAccessKey:accessKey AccessSecret:accessSecret ProviderError:error];
NetworkCompressionStrategy 基于AFNetworkReachabilityStatus提供了默认压缩策略
DefaultCompressionStrategy 不压缩
若需要自定义压缩策略
遵循CompressionStrategy协议重写-(NSData *)compressionStrategyPercentWithImage:(UIImage *)image;
NSString *endpoint = @"";
NSString *bucket = @"";
NSString *bucketUrl = @"";
NetworkCompressionStrategy *strategy = [[NetworkCompressionStrategy alloc] init];
[[XMX_AliYunOSSUtils sharedInstance] registerWithEndpoint:endpoint ImageBucket:bucket FileBucket:bucket VedioBucket:bucket ImageBucketUrl:bucketUrl FileBucketUrl:bucketUrl VedioBucketUrl:bucketUrl CompressionStrategy:strategy CredentialProvider:credentialProviderByServer];
[[XMX_AliYunOSSUtils sharedInstance] uploadImage: withKey: uploadProgress:^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
NSLog(@"上传中。。。");
} uploadComplete:^(NSError *error, NSString *url, NSString *key) {
if (error) {
NSLog(@"上传失败。。。");
return ;
}
NSLog(@"上传成功。。。url = %@ key = %@",url,key);
}];
736497373, 736497373@qq.com
XMX_AliYunOSS is available under the MIT license. See the LICENSE file for more info.