华为云图片上传数组越界错误

2021-09-01  本文已影响0人  梵虚

最近使用华为云发现一个数组越界的错误,代码完全参照官方的demo,就是提示失败,后面发现是URL的问题,安卓在HuaWeiEndpoint的时候不需要加Http头,但是苹果这边必须要加,否则会出现数组越界的错误

 OBSStaticCredentialProvider *creadentailProvider = [[OBSStaticCredentialProvider alloc] initWithAccessKey:HuaWeiAccess_key_id secretKey:HuaWeiSecret_key authVersion:OBSAuthVersionV4];
            OBSServiceConfiguration *conf = [[OBSServiceConfiguration alloc] initWithURL:[NSURL URLWithString:HuaWeiEndpoint] credentialProvider:creadentailProvider];
            OBSClient *client = [[OBSClient alloc] initWithConfiguration:conf];
            NSString *strKey = [NSString stringWithFormat:@"user/%@avator%ld.jpg",self.mineModel.uid,theFianl];
            OBSPutObjectWithFileRequest *requestUplodad = [[OBSPutObjectWithFileRequest alloc] initWithBucketName:HuaWeiBucket objectKey:strKey uploadFilePath:strFilePath];
            requestUplodad.storageClass = OBSStorageClassGlacier;
            requestUplodad.uploadProgressBlock = ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
                NSLog(@"%0.1f%%",(float)floor(totalBytesSent*10000/totalBytesExpectedToSend)/100);
            };
            OBSBFTask *pushTask = [client putObject:requestUplodad completionHandler:^(OBSPutObjectResponse *response, NSError *error) {
                if (error) {
                    NSLog(@"error is %@",error.description);
                }else{
                    NSString *imagePath = [NSString stringWithFormat:@"/user/%@avator%ld.jpg",self.mineModel.uid,theFianl];
                   NSLog(@"imagePath = %@",imagePath);
                }
                [[NSFileManager defaultManager] removeItemAtPath:strFilePath error:nil];
            }];
            [pushTask waitUntilFinished];
上一篇下一篇

猜你喜欢

热点阅读