Os links simbólicos funcionam como atalhos de arquivos no Windows e permitem acessar rapidamente os objetos associados no Object Storage Service (OSS).
Observações de uso
Antes de executar os exemplos deste tópico, crie uma instância do OSSClient. Use um nome de domínio personalizado ou o Security Token Service (STS). Para obter mais informações, consulte Initialization (Android SDK).
Crie um link simbólico
O código de exemplo a seguir demonstra como criar um link simbólico:
// Create a request.
PutSymlinkRequest putSymlink = new PutSymlinkRequest();
// Specify the name of the bucket.
putSymlink.setBucketName("yourBucketName");
// Specify the name of the symbolic link.
putSymlink.setObjectKey("yourSymLink");
// Specify the name of the object to which you want the symbolic link to point.
putSymlink.setTargetObjectName("yourTargetObjectName");
ObjectMetadata metadata = new ObjectMetadata();
// Specify whether to overwrite the object that has the same name. In this example, this parameter is set to true, which indicates that the object that has the same name cannot be overwritten.
//metadata.setHeader("x-oss-forbid-overwrite", "true");
// Specify the access control list (ACL) of the object. In this example, the ACL is set to private.
//metadata.setHeader("x-oss-object-acl", "private");
// Specify the storage class of the object. In this example, the storage class is set to Standard.
//metadata.setHeader("x-oss-storage-class", "Standard");
putSymlink.setMetadata(metadata);
OSSAsyncTask task = oss.asyncPutSymlink(putSymlink, new OSSCompletedCallback<PutSymlinkRequest, PutSymlinkResult>() {
@Override
public void onSuccess(PutSymlinkRequest request, PutSymlinkResult result) {
Log.d("PutSymlink", "PutSymlink success");
}
@Override
public void onFailure(PutSymlinkRequest request, ClientException clientException,
ServiceException serviceException) {
// Handle request exceptions.
if (clientException != null) {
// Handle client exceptions, such as network exceptions.
clientException.printStackTrace();
}
if (serviceException != null) {
// Handle server-side exceptions.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
task.waitUntilFinished();
Consulte o nome do objeto para o qual um link simbólico aponta
Para consultar um link simbólico, você deve ter permissões de leitura no link. O código de exemplo a seguir demonstra como consultar o nome do objeto para o qual um link simbólico aponta:
// Create a request.
GetSymlinkRequest getSymlink = new GetSymlinkRequest();
// Specify the name of the bucket.
getSymlink.setBucketName("yourBucketName");
// Specify the name of the symbolic link.
getSymlink.setObjectKey("yourSymLink");
OSSAsyncTask task = oss.asyncGetSymlink(getSymlink, new OSSCompletedCallback<GetSymlinkRequest,
GetSymlinkResult>() {
@Override
public void onSuccess(GetSymlinkRequest request, GetSymlinkResult result) {
OSSLog.logInfo("targ::"+result.getTargetObjectName());
}
@Override
public void onFailure(GetSymlinkRequest request, ClientException clientException,
ServiceException serviceException) {
OSSLog.logError("error: "+serviceException.getRawMessage());
}
});
task.waitUntilFinished();
Referências
Para acessar o código de exemplo completo para gerenciar links simbólicos, visite o GitHub.
Para obter mais informações sobre a operação da API para criar um link simbólico, consulte PutSymlink.
Para obter detalhes sobre a operação da API para consultar um link simbólico, consulte GetSymlink.
Para saber mais sobre como inicializar uma instância do OSSClient, consulte Initialization.