拷贝对象
对象是存储数据的基本单元。对象由元信息(Object Meta),用户数据(Data)和文件名(Key)组成。对象由桶内部唯一的Key来标识。本文介绍如何拷贝对象。
接口定义:
- (void)replicateObject:(AWSS3ReplicateObjectRequest *)request
completionHandler:(void (^)(AWSS3ReplicateObjectOutput *response, NSError *error))completionHandler
参数:
参数名 | 类型 | 说明 |
---|---|---|
bucket | NSString | 目的bucket |
key | NSString | 目的对象名 |
replicateSource | NSString | 源bucket和对象名,使用/分割 |
代码示例:
- (void) copyObjectWithBucket:(NSString*)bucketName
key:(NSString*)keyName
sourceBucket:(NSString*)sourceBucketName
sourceKey:(NSString*)sourceKey {
AWSS3ReplicateObjectRequest *request = [[AWSS3ReplicateObjectRequest alloc] init];
request.bucket = bucketName;
request.key = keyName;
request.replicateSource = [NSString stringWithFormat:@"%@/%@", sourceBucketName, sourceKey];
[self.s3 replicateObject:request completionHandler:^(AWSS3ReplicateObjectOutput * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"error: %@", error);
return;
}
}];
}