oss获取Object的Meta信息,就是我们在上传照片的时特殊设置

来源:互联网 发布:线切割手动编程说明书 编辑:程序博客网 时间:2024/05/17 07:06


  NSString *endpoint =@"";

    // 明文设置secret的方式建议只在测试时使用,更多鉴权模式请参考后面的`访问控制`章节

  //    NSLog(@"--%@--%@--%@",self.accessKeyId,self.accessKeySecret,self.securityToken);

    id<OSSCredentialProvider> credential = [[OSSStsTokenCredentialProvideralloc] initWithAccessKeyId:self.accessKeyIdsecretKeyId:self.accessKeySecretsecurityToken:self.securityToken];

   //设置网络请求的一些参数

    OSSClientConfiguration * conf=[OSSClientConfigurationnew];

    

    //最大重试次数

    conf.maxRetryCount=3;

    

    conf.timeoutIntervalForRequest=30;//网络请求的超时时间

    

    OSSClient* client = [[OSSClientalloc] initWithEndpoint:endpointcredentialProvider:credential];


    OSSHeadObjectRequest * head = [OSSHeadObjectRequestnew];

    head.bucketName = @"<bucketName>";

    head.objectKey = @"<objectKey>";

    OSSTask * headTask = [client headObject:head];

   [headTask continueWithBlock:^id(OSSTask *task) {

    if (!task.error) {

        OSSHeadObjectResult * headResult = task.result;

        NSLog(@"all response header: %@", headResult.httpResponseHeaderFields);

        // some object properties include the 'x-oss-meta-*'s

        NSLog(@"head object result: %@", headResult.objectMeta);

    } else {

        NSLog(@"head object error: %@", task.error);

    }

    returnnil;

  }];