Todos os produtos
Search
Central de documentação

Object Storage Service:Renomear um objeto (Android SDK)

Última atualização: Jul 03, 2026

O OSS não permite renomear objetos diretamente. Para renomear um objeto, copie-o e exclua o original: chame CopyObject para criar um novo objeto com o nome desejado e, em seguida, chame DeleteObject para remover o objeto source.

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).

Código de exemplo

O código a seguir renomeia srcobject.txt para destobject.txt no bucket examplebucket:

// Specify the name of the bucket.
String bucketName = "examplebucket";
// Specify the full path of the source object. Do not include the bucket name in the full path. Example: srcobject.txt.
String sourceObjectKey = "srcobject.txt";
// Specify the full path of the destination object. Do not include the bucket name in the full path. Example: destobject.txt.
String objectKey = "destobject.txt";
try {
    CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucketName, sourceObjectKey, bucketName, objectKey);
    oss.copyObject(copyObjectRequest);
    // Delete the srcobject.txt object.
    DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucketName, sourceObjectKey);
    oss.deleteObject(deleteObjectRequest);
} catch (ClientException e) {
    // Handle client-side exceptions, such as network errors.
    e.printStackTrace();
} catch (ServiceException e) {
    // Handle server-side exceptions.
    Log.e("RequestId", e.getRequestId());
    Log.e("ErrorCode", e.getErrorCode());
    Log.e("HostId", e.getHostId());
    Log.e("RawMessage", e.getRawMessage());
}
Nota

Diretórios também não podem ser renomeados diretamente. Aplique a mesma abordagem de cópia e exclusão para cada objeto e subdiretório.

Referências