开发者社区> 问答> 正文

阿里云 oss 断点续传视频报错,求帮助啊

viewDidLoad的时候调用server接口获取的objectKey,bucketName,AccessKeyId,AccessKeySecret,SecurityToken,Expiration等信息存放在dicResult字典中;设置STS鉴权模式。

//STS鉴权模式
-(void)STSTokenCredentialProvider {
     NSString *endpoint = [dicResult objectForKey:@"endpoint"];
    id<OSSCredentialProvider> credential2 = [[OSSFederationCredentialProvider alloc] initWithFederationTokenGetter:^OSSFederationToken * {
        
        //server接口获取的信息存放在dicResult字典中
        [self authorizeAPISuccess:nil Faild:nil];
        
        OSSFederationToken * token = [OSSFederationToken new];
        token.tAccessKey = [dicResult objectForKey:@"AccessKeyId"];
        token.tSecretKey = [dicResult objectForKey:@"AccessKeySecret"];
        token.tToken = [dicResult objectForKey:@"SecurityToken"];
        NSString *string = [dicResult objectForKey:@"Expiration"];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *date=[formatter dateFromString:string];
        token.expirationTimeInMilliSecond = [date timeIntervalSince1970];
        NSLog(@"get token: %@", token);

        return token;
        
    }];

    client = [[OSSClient alloc] initWithEndpoint:endpoint credentialProvider:credential2];
}

然后点击上传按钮调用下面方法

//断点续传视频
-(void)multipartUploadVideo {

    __block NSString * uploadId = nil;
    
    OSSInitMultipartUploadRequest * init = [OSSInitMultipartUploadRequest new];
    init.bucketName = dicResult[@"bucketName"];
    init.objectKey = dicResult[@"objectKey"];

    
    // 先获取到用来标识整个上传事件的UploadId
    OSSTask * task = [client multipartUploadInit:init];
    [[task continueWithBlock:^id(OSSTask *task) {
        if (!task.error) {
            OSSInitMultipartUploadResult * result = task.result;
            uploadId = result.uploadId;
        } else {
            NSLog(@"init uploadid failed, error: %@", task.error);
        }
        
        
        return nil;
    }] waitUntilFinished];
    
    // 获得UploadId进行上传,如果任务失败并且可以续传,利用同一个UploadId可以上传同一文件到同一个OSS上的存储对象
    OSSResumableUploadRequest * resumableUpload = [OSSResumableUploadRequest new];
    resumableUpload.bucketName = dicResult[@"bucketName"];
    resumableUpload.objectKey = dicResult[@"objectKey"];
    resumableUpload.uploadId = uploadId;
    resumableUpload.partSize = 1024 * 1024;
    resumableUpload.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
        NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
    };
    
    resumableUpload.uploadingFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"VID_20160226_134406.mp4"]];
    OSSTask * resumeTask = [client resumableUpload:resumableUpload];
    [resumeTask continueWithBlock:^id(OSSTask *task) {
        if (task.error) {
            NSLog(@"error: %@", task.error);
            if ([task.error.domain isEqualToString:OSSClientErrorDomain] && task.error.code == OSSClientErrorCodeCannotResumeUpload) {
                //
                NSLog(@"该任务无法续传,需要获取新的uploadId重新上传");
            }
        } else {
            NSLog(@"Upload file success");
        }
        return nil;
    }];
  
    // [resumeTask waitUntilFinished];
    // [resumableUpload cancel];
}

然而在第一个block里就报错了
Error Domain=com.aliyun.oss.serverError Code=-403 "(null)" UserInfo={__name=Error, HostId=em-video-upload-private.oss-cn-hangzhou.aliyuncs.com, Message=Access denied by authorizer's policy., Code=AccessDenied, RequestId=56D3B522F9EEA2C908C866B8}

展开
收起
张林峰 2016-02-29 11:05:01 11157 0
2 条回答
写回答
取消 提交回答
  • 阿里云对象存储(OSS)开发工程师
    应该是你的token并没有multipart的上传权限,你可以检查一下你的token使用的policy是否正确
    2016-02-29 18:22:56
    赞同 展开评论 打赏
  • Alibaba Cloud OSS SDK/Tools Developer
    Re阿里云 oss 断点续传视频报错,求帮助啊
    你好,AccessDenied是没有权限,你确认你有上传权限。
    2016-02-29 17:05:25
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
阿里云云原生 Serverless 技术实践营 PPT 演讲 立即下载
阿里云产品十月刊 立即下载
基于阿里云构建博学谷平台实时湖仓 立即下载