对象元信息是对象的属性描述,包括HTTP标准属性(HTTP Header)和用户自定义元数据(User Meta)两种。本文介绍设置对象元信息的示例代码。
在上传对象时,为对象添加自定义元信息,用于标识对象的用途或属性等。
如下代码展示如何设置对象的自定义元信息。
// 从STS服务获取的临时访问密钥和安全令牌(AccessKey、SecretKey、SecurityToken) TOSCredential *credential = [[TOSCredential alloc] initWithAccessKey:@"accesskey" secretKey:@"secretkey" securityToken:@"securityToken"]; TOSEndpoint *tosEndpoint = [[TOSEndpoint alloc] initWithURLString:@"endpoint" withRegion:@"region"]; TOSClientConfiguration *config = [[TOSClientConfiguration alloc] initWithEndpoint:tosEndpoint credential:credential]; TOSClient *client = [[TOSClient alloc] initWithConfiguration:config]; TOSSetObjectMetaInput *set = [TOSSetObjectMetaInput new]; set.tosBucket = @"bucket-name"; set.tosKey = @"object-name"; set.tosMeta = @{@"user-key-1":@"use-val-1", @"user-key-2":@"use-val-2"}; TOSTask *task = [_client setObjectMeta:set]; [task continueWithBlock:^id _Nullable(TOSTask * _Nonnull task) { if (!task.error) { NSLog(@"Set object meta success."); TOSSetObjectMetaOutput *output = task.result; } else { NSLog(@"Set object meta failed, error: %@", task.error); } return nil; }];