|
@@ -46,15 +46,10 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
--(void)getOSSInfo{
|
|
|
|
|
|
|
+-(void)getOSSInfo:(void (^_Nullable)(bool))success{
|
|
|
if (!_uploadTanck) {
|
|
if (!_uploadTanck) {
|
|
|
_uploadTanck = [NSMutableArray new];
|
|
_uploadTanck = [NSMutableArray new];
|
|
|
}
|
|
}
|
|
|
- NSDictionary *dic = [UDManager.shareInstance getDDManager:nkOSSinfo];
|
|
|
|
|
- if(dic){
|
|
|
|
|
- self.OSSInfo = dic.copy;
|
|
|
|
|
- [self initmyAliyunOSS];
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
[OssNetApi getOSSInfo:nil succ:^(int code, NSDictionary * res) {
|
|
[OssNetApi getOSSInfo:nil succ:^(int code, NSDictionary * res) {
|
|
|
NSLog(@"res:%@",res);
|
|
NSLog(@"res:%@",res);
|
|
@@ -62,12 +57,15 @@
|
|
|
if(codeV.intValue==200){
|
|
if(codeV.intValue==200){
|
|
|
self.OSSInfo = res[@"data"];
|
|
self.OSSInfo = res[@"data"];
|
|
|
if(self.OSSInfo){
|
|
if(self.OSSInfo){
|
|
|
- [self initmyAliyunOSS];
|
|
|
|
|
[UDManager.shareInstance setDDManager:self.OSSInfo key:nkOSSinfo];
|
|
[UDManager.shareInstance setDDManager:self.OSSInfo key:nkOSSinfo];
|
|
|
|
|
+ success(true);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ else{
|
|
|
|
|
+ success(false);
|
|
|
|
|
+ }
|
|
|
} fail:^(NSError * _Nonnull error) {
|
|
} fail:^(NSError * _Nonnull error) {
|
|
|
-
|
|
|
|
|
|
|
+ success(false);
|
|
|
}];
|
|
}];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -88,13 +86,18 @@
|
|
|
|
|
|
|
|
id<OSSCredentialProvider> credentialProvider = [[OSSStsTokenCredentialProvider alloc] initWithAccessKeyId:accessKeyId secretKeyId:accessKeySecret securityToken:securityToken];
|
|
id<OSSCredentialProvider> credentialProvider = [[OSSStsTokenCredentialProvider alloc] initWithAccessKeyId:accessKeyId secretKeyId:accessKeySecret securityToken:securityToken];
|
|
|
OSSClientConfiguration *cfg = [[OSSClientConfiguration alloc] init];
|
|
OSSClientConfiguration *cfg = [[OSSClientConfiguration alloc] init];
|
|
|
- cfg.maxRetryCount = 3;
|
|
|
|
|
|
|
+ cfg.maxRetryCount = 5;
|
|
|
cfg.timeoutIntervalForRequest = 15;
|
|
cfg.timeoutIntervalForRequest = 15;
|
|
|
cfg.isHttpdnsEnable = NO;
|
|
cfg.isHttpdnsEnable = NO;
|
|
|
cfg.crc64Verifiable = YES;
|
|
cfg.crc64Verifiable = YES;
|
|
|
|
|
|
|
|
OSSClient *defaultClient = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credentialProvider clientConfiguration:cfg];
|
|
OSSClient *defaultClient = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credentialProvider clientConfiguration:cfg];
|
|
|
[OSSManager sharedManager].defaultClient = defaultClient;
|
|
[OSSManager sharedManager].defaultClient = defaultClient;
|
|
|
|
|
+
|
|
|
|
|
+ NSDate *now = [NSDate date];
|
|
|
|
|
+ NSTimeInterval trt = [now timeIntervalSince1970];
|
|
|
|
|
+ self.initIme = trt;
|
|
|
|
|
+
|
|
|
//旧的图片服务
|
|
//旧的图片服务
|
|
|
// OSSClient *defaultImgClient = [[OSSClient alloc] initWithEndpoint:oldimgendpoint credentialProvider:credentialProvider clientConfiguration:cfg];
|
|
// OSSClient *defaultImgClient = [[OSSClient alloc] initWithEndpoint:oldimgendpoint credentialProvider:credentialProvider clientConfiguration:cfg];
|
|
|
// [OSSManager sharedManager].imageClient = defaultImgClient;
|
|
// [OSSManager sharedManager].imageClient = defaultImgClient;
|
|
@@ -104,13 +107,40 @@
|
|
|
|
|
|
|
|
//普通上传
|
|
//普通上传
|
|
|
- (void)asyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
|
|
- (void)asyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
|
|
|
- if([OSSManager sharedManager].defaultClient==nil){
|
|
|
|
|
- [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
|
|
|
|
|
- [self getOSSInfo];
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if([self chectToken]){
|
|
|
|
|
+ if([OSSManager sharedManager].defaultClient==nil){
|
|
|
|
|
+ [self getOSSInfo:^(bool code){
|
|
|
|
|
+ if(code){
|
|
|
|
|
+ [self initmyAliyunOSS];
|
|
|
|
|
+ [self prasyncPutFile:objectKey localFilePath:filePath thrid:strtime];
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
|
|
|
|
|
+ }
|
|
|
|
|
+ }];
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ [self prasyncPutFile:objectKey localFilePath:filePath thrid:strtime];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ else{
|
|
|
|
|
+ [self getOSSInfo:^(bool code){
|
|
|
|
|
+ if(code){
|
|
|
|
|
+ [self initmyAliyunOSS];
|
|
|
|
|
+ [self prasyncPutFile:objectKey localFilePath:filePath thrid:strtime];
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
|
|
|
|
|
+ }
|
|
|
|
|
+ }];
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+-(void)prasyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
|
|
|
|
|
+
|
|
|
if (![objectKey oss_isNotEmpty]) {
|
|
if (![objectKey oss_isNotEmpty]) {
|
|
|
- NSError *error = [NSError errorWithDomain:NSInvalidArgumentException code:0 userInfo:@{NSLocalizedDescriptionKey: @"objectKey should not be nil"}];
|
|
|
|
|
if(self.delegate){
|
|
if(self.delegate){
|
|
|
NSDictionary *dic=@{
|
|
NSDictionary *dic=@{
|
|
|
@"state":@"3",
|
|
@"state":@"3",
|
|
@@ -176,14 +206,44 @@
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
//断点续传
|
|
//断点续传
|
|
|
- (void)asyncResumableUploadFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
|
|
- (void)asyncResumableUploadFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
|
|
|
|
|
|
|
|
- if([OSSManager sharedManager].defaultClient==nil){
|
|
|
|
|
- [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
|
|
|
|
|
- [self getOSSInfo];
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if([self chectToken]){
|
|
|
|
|
+ if([OSSManager sharedManager].defaultClient==nil){
|
|
|
|
|
+ [self getOSSInfo:^(bool code){
|
|
|
|
|
+ if(code){
|
|
|
|
|
+ [self initmyAliyunOSS];
|
|
|
|
|
+ [self PrasyncResumableUploadFile:objectKey localFilePath:filePath thrid:strtime];
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
|
|
|
|
|
+ }
|
|
|
|
|
+ }];
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ [self PrasyncResumableUploadFile:objectKey localFilePath:filePath thrid:strtime];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ else{
|
|
|
|
|
+ [self getOSSInfo:^(bool code){
|
|
|
|
|
+ if(code){
|
|
|
|
|
+ [self initmyAliyunOSS];
|
|
|
|
|
+ [self PrasyncResumableUploadFile:objectKey localFilePath:filePath thrid:strtime];
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
|
|
|
|
|
+ }
|
|
|
|
|
+ }];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+-(void)PrasyncResumableUploadFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
|
|
|
|
|
|
|
|
// 获取UploadId上传文件。
|
|
// 获取UploadId上传文件。
|
|
|
OSSResumableUploadRequest * resumableUpload = [OSSResumableUploadRequest new];
|
|
OSSResumableUploadRequest * resumableUpload = [OSSResumableUploadRequest new];
|
|
@@ -254,6 +314,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
-(void)addUploadTanckobj:(OSSTask *)task thrid:(NSString *)thrid{
|
|
-(void)addUploadTanckobj:(OSSTask *)task thrid:(NSString *)thrid{
|
|
|
NSDictionary *item = @{
|
|
NSDictionary *item = @{
|
|
|
@"task":task,
|
|
@"task":task,
|
|
@@ -372,5 +434,28 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+-(BOOL)chectToken{
|
|
|
|
|
+
|
|
|
|
|
+ if(self.initIme>0){
|
|
|
|
|
+ NSDate *now = [NSDate date];
|
|
|
|
|
+ NSTimeInterval trt = [now timeIntervalSince1970];
|
|
|
|
|
+ NSInteger time = trt;
|
|
|
|
|
+ time =time-self.initIme;
|
|
|
|
|
+ NSLog(@"chectToken------:%ld",(long)time);
|
|
|
|
|
+ if(time>2000){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@end
|
|
@end
|