Links simbólicos funcionam como atalhos de arquivo no Windows e permitem acessar rapidamente os objetos associados no Object Storage Service (OSS).
Usage note
Antes de executar o código de exemplo deste tópico, crie uma instância do OSSClient usando métodos como domínio personalizado ou Security Token Service (STS). Para obter mais informações, consulte Initialization.
Create a symbolic link
O código a seguir apresenta um exemplo de como criar um link simbólico chamado examplesymlink que aponta para um objeto chamado exampleobject.txt em um bucket chamado examplebucket:
OSSPutSymlinkRequest *request = [OSSPutSymlinkRequest new];
// Specify the name of the bucket. Example: examplebucket.
request.bucketName = @"examplebucket";
// Specify the name of the symbolic link.
request.objectKey = @"examplesymlink";
// Specify the full path of the object to which you want the symbolic link to point. Do not include the bucket name in the full path.
request.targetObjectName = @"exampleobject.txt";
OSSTask *putSymlinkTask = [client putSymlink:request];
[putSymlinkTask continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
if (!task.error) {
NSLog(@"put symlink success");
} else {
NSLog(@"put symlink failed, error: %@", task.error);
}
return nil;
}];
// Implement synchronous blocking to wait for the task to complete.
// [putSymlinkTask waitUntilFinished];
Query a symbolic link
Para consultar o objeto para o qual um link simbólico aponta, você precisa ter permissões de leitura sobre o link simbólico.
O código a seguir apresenta um exemplo de como consultar o nome do objeto para o qual um link simbólico chamado examplesymlink aponta no bucket examplebucket:
OSSGetSymlinkRequest *request = [OSSGetSymlinkRequest new];
// Specify the name of the bucket. Example: examplebucket.
request.bucketName = @"examplebucket";
// Specify the name of the symbolic link.
request.objectKey = @"examplesymlink";
OSSTask *getSymlinkTask = [client getSymlink:request];
[getSymlinkTask continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
if (!task.error) {
OSSGetSymlinkResult *result = task.result;
NSLog(@"get symlink: %@", result.httpResponseHeaderFields[@"x-oss-symlink-target"]);
} else {
NSLog(@"get symlink failed, error: %@", task.error);
}
return nil;
}];
// Implement synchronous blocking to wait for the task to complete.
// [putSymlinkTask waitUntilFinished];
References
Para obter mais informações sobre a operação de API que pode ser chamada para criar um link simbólico, consulte PutSymlink.
Para obter mais informações sobre a operação de API que pode ser chamada para consultar um link simbólico, consulte GetSymlink.
Para obter mais informações sobre como inicializar uma instância do OSSClient, consulte Initialization.