开发者社区> 问答> 正文

IOS OSS上传图片出现问题,求助

NSDictionary * alidict1 = [aliDict objectForKey:@"Credentials"];
        NSString * accessKeyId = [alidict1 objectForKey:@"AccessKeyId"];
        NSString * expiration = [alidict1 objectForKey:@"Expiration"];
        NSString * SecurityToken = [alidict1 objectForKey:@"SecurityToken"];
        NSString * accessKeySecret = [alidict1 objectForKey:@"AccessKeySecret"];
        OSSFederationToken * token = [OSSFederationToken new];
        token.tAccessKey = accessKeyId;
        token.tSecretKey = accessKeySecret;
        token.tToken = SecurityToken;
        token.expirationTimeInGMTFormat = expiration;
        NSLog(@"get token:%@",token);
        id<OSSCredentialProvider> credential = [[OSSFederationCredentialProvider alloc]initWithFederationTokenGetter:^OSSFederationToken *{
            return token;
        }];
        NSString *endpoint = ALIYUN_END_POINT;

        OSSClient * client = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credential];
        OSSPutObjectRequest * put = [OSSPutObjectRequest new];
        put.bucketName = ALIYUN_BUCKET;

        put.objectKey = fileName;
        
        NSString * docDir = [self getDocumentDirectory];
        put.uploadingFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:fileName]];
        
        NSLog(@"put.uploadingFileURL:%@",put.uploadingFileURL);
        put.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
            // 当前上传段长度、当前已经上传总长度、一共需要上传的总长度
            NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
        };
//        put.
        OSSTask * putTask = [client putObject:put];
        [putTask continueWithBlock:^id(OSSTask *task) {
            if (!task.error) {
                NSLog(@"upload object success!");
            }else{
                NSLog(@"upload object failed, error: %@",task.error);
            }
            return nil;
        }];
        [putTask waitUntilFinished];
出现这个问题upload object failed, error: Error Domain=com.aliyun.oss.serverError Code=-403 "(null)" UserInfo={__name=Error, HostId=healthd-user-pic-stage.oss-cn-hangzhou.aliyuncs.com, Message=Access denied by authorizer's policy., Code=AccessDenied, RequestId=56722C6DD4C05B286BEEE823},这是什么原因呢

展开
收起
飞起的落叶 2015-12-17 11:28:35 18751 0
4 条回答
写回答
取消 提交回答
  • 回 2楼克劳德小弟的帖子
    子用户需要调用STS:AssumeRole接口,所以子用户只需要有STS AssumeRole的权限就好

    Token是扮演角色而获得,所以Token的权限是角色的子集,而非交集,当不指定Policy参数时,Token的权限与角色权限相同。

    当撤销角色的权限时,Token自动失效。
    2015-12-21 21:01:36
    赞同 展开评论 打赏
  • 回 2楼克劳德小弟的帖子
    ios版的怎么打开日志呢,我想查看一下图片的上传路径
    2015-12-17 13:57:28
    赞同 展开评论 打赏
  • 在你调用assumeRole接口获取Sts token时,有三个权限相关参数:子账户、角色、Policy,token最终拥有的权限由三者交集决定。

    所以请检查一下,子账户是否用户OSS写权限、角色是否拥有OSS写权限、policy是否拥有该Bucket、该Object写权限。

    -------------------------

    在初始化的时候,调用OSSLog.enableLog();

    2015-12-17 13:23:58
    赞同 展开评论 打赏
  • ReIOS OSS上传图片出现问题,求助
    看样子是因为你用的STS token里的policy权限不够,检查一下你的policy和这个写操作请求的资源吧
    2015-12-17 13:02:04
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载