Todos os produtos
Search
Central de documentação

Object Storage Service:Gerencie links simbólicos usando o OSS SDK for Android

Última atualização: Jul 03, 2026

Os links simbólicos funcionam como atalhos de arquivo no Windows e permitem acessar rapidamente objetos associados no Object Storage Service (OSS).

Observações de uso

  • Antes de executar o código de exemplo deste tópico, crie uma instância OSSClient por meio de métodos como nome de domínio personalizado ou Security Token Service (STS). Para mais informações, consulte Inicialização (Android SDK).

Crie um link simbólico

O 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();

Consultar o nome do objeto apontado por um link simbólico

A consulta de um link simbólico exige permissões de leitura sobre ele. O exemplo a seguir mostra como obter 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 visualizar o código de exemplo completo sobre gerenciamento de links simbólicos, acesse o repositório no GitHub.

  • Para obter detalhes sobre como criar um link simbólico, consulte a operação da API PutSymlink.

  • Sobre a consulta de links simbólicos via API, veja GetSymlink.

  • Para saber mais sobre como inicializar uma instância OSSClient, consulte Inicialização.