You need to enable JavaScript to run this app.
导航

获取图片信息(iOS SDK)

最近更新时间2024.02.04 18:31:09

首次发布时间2023.11.03 16:08:03

获取图片信息功能可以获取到图片的基本信息,包括图片的长、宽、大小和格式。如果图片包含 Exif 信息,将按照 JSON 字符串返回内容。

示例代码

以下代码展示如何获取图片信息。

// 从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];

TOSGetObjectInput *get = [TOSGetObjectInput new];
get.tosBucket = @"bucket-name";
get.tosKey = @"image-name";
get.tosProcess = @"image/info";
TOSTask *task = [client getObject:get];
[task continueWithBlock:^id _Nullable(TOSTask * _Nonnull t) {
    if (!task.error) {
        NSLog(@"Get object success.");
        // 获取图片信息
        TOSGetObjectOutput *out = t.result;
        NSLog(@"%@", [[NSString alloc] initWithData:out.tosContent encoding:NSUTF8StringEncoding]);
    } else {
        NSLog(@"Get object failed, error: %@" ,task.error);
    }
    return nil;
}];

相关文档

关于获取图片信息的详细介绍,请参见获取信息