美文网首页
阿里云上传问题

阿里云上传问题

作者: 倒着游的鱼 | 来源:发表于2022-06-27 21:37 被阅读0次

upload object failed, error: Error Domain=com.aliyun.oss.clientError Code=9 "(null)" UserInfo={ErrorMessage=Catch exception - Task created in a session that has been invalidated}

解决方案:用单例持有client,然后问题就解决了
如果还是存在的话
1、可能client提前释放了?应该是作用域的问题
2、 加上 [putTask waitUntilFinished]; // 阻塞直到上传完成

以下使用token缓存方式 导致阿里云内部闪退问题

 OSSFederationToken * token = [OSSFederationToken new];
            // All the entries below are mandatory.
            token.tAccessKey = accessKeyId;
            token.tSecretKey = secretKeyId;
            token.tToken = securityToken;
            token.expirationTimeInGMTFormat = Expiration;
            
            OSSFederationCredentialProvider *CredentialProvider = [[OSSFederationCredentialProvider alloc]init];
            CredentialProvider.cachedToken = token;
            
            id<OSSCredentialProvider> credential = CredentialProvider;
            
            OSSClientConfiguration *conf = [OSSClientConfiguration new];
            conf.maxRetryCount = 3; // 网络请求遇到异常失败后的重试次数
            conf.timeoutIntervalForRequest = 20; // 网络请求的超时时间
            conf.timeoutIntervalForResource = 24*60*60; // 允许资源传输的最长时间
            conf.maxConcurrentRequestCount = 30;
            
            cutoutClient = [[OSSClient alloc] initWithEndpoint:endossPoint credentialProvider:credential clientConfiguration:conf];

修改:

id<OSSCredentialProvider> credential2 = [[OSSFederationCredentialProvider alloc] initWithFederationTokenGetter:^OSSFederationToken * {
                        
                        OSSFederationToken * token = [OSSFederationToken new];
                        token.tAccessKey = ossToken.AccessKeyId;
                        token.tSecretKey = ossToken.AccessKeySecret;
                        token.tToken = ossToken.SecurityToken;
                        token.expirationTimeInGMTFormat = ossToken.Expiration;
                        
                        NSLog(@"cutoutClient == nil get token: %@", token);
                        return token;
                    }];
                    
                    OSSClientConfiguration *conf = [OSSClientConfiguration new];
                    conf.maxRetryCount = 3; // 网络请求遇到异常失败后的重试次数
                    conf.timeoutIntervalForRequest = 20; // 网络请求的超时时间
                    conf.timeoutIntervalForResource = 24*60*60; // 允许资源传输的最长时间
                    conf.maxConcurrentRequestCount = 30;
                    cutoutClient = [[OSSClient alloc] initWithEndpoint:endossPoint credentialProvider:credential2 clientConfiguration:conf];

解决!

相关文章

网友评论

      本文标题:阿里云上传问题

      本文链接:https://www.haomeiwen.com/subject/gnpovrtx.html