2010-03-20 24 views
68

¿Cómo se cambia el nombre de una clave S3 en un cubo con boto?Amazon S3 boto: ¿Cómo se cambia el nombre de un archivo en un depósito?

+1

Elegido para volver a abrir, esta es una pregunta bastante simple que no es tan ambigua. Ir a editar para mencionar explícitamente ese archivo significa la clave s3. – David

+0

En caso de que alguien se lo esté preguntando, puede hacerlo a través de la interfaz web de AWS (haga clic con el botón derecho en el archivo -> Cambiar nombre) –

Respuesta

67

No puede cambiar el nombre de los archivos en Amazon S3. Puede copiarlos con un nuevo nombre, luego eliminar el original, pero no hay una función de cambio de nombre adecuada.

+10

Solo tenga en cuenta que la función de copia parece instantánea (quizás un enlace simbólico). Entonces no hay problema con la velocidad haciendo esto. –

+17

En el momento de este comentario, NO parece ser instantáneo. Estoy copiando un archivo de 2GB y me está tomando varios minutos. – dtbarne

+0

1) ¿Puede alguien decirme cuánto tiempo tomaría copiar y pegar un archivo de 3 GB en el mismo contenedor y en la misma ubicación? y luego borre el archivo original. 2) Parece que la interfaz de usuario tiene una funcionalidad de cambio de nombre. Pero la interfaz de usuario también funciona de la misma manera (copiar y eliminar) en segundo plano. – shiva

-6
//Copy the object 
AmazonS3Client s3 = new AmazonS3Client("AWSAccesKey", "AWSSecretKey"); 

CopyObjectRequest copyRequest = new CopyObjectRequest() 
     .WithSourceBucket("SourceBucket") 
     .WithSourceKey("SourceKey") 
     .WithDestinationBucket("DestinationBucket") 
     .WithDestinationKey("DestinationKey") 
     .WithCannedACL(S3CannedACL.PublicRead); 
s3.CopyObject(copyRequest); 

//Delete the original 
DeleteObjectRequest deleteRequest = new DeleteObjectRequest() 
     .WithBucketName("SourceBucket") 
     .WithKey("SourceKey"); 
s3.DeleteObject(deleteRequest); 
+20

-1: esta es una solución con [AWS SDK for .NET] (http://aws.amazon.com/sdkfornet/) en lugar de la solución solicitada con [boto] (https://github.com/boto/boto), que _es un paquete de Python que proporciona interfaces a Amazon Web Services_. –

38

Aquí es un ejemplo de una función de Python que copiar un objeto S3 usando Boto 2:

import boto 

def copy_object(src_bucket_name, 
       src_key_name, 
       dst_bucket_name, 
       dst_key_name, 
       metadata=None, 
       preserve_acl=True): 
    """ 
    Copy an existing object to another location. 

    src_bucket_name Bucket containing the existing object. 
    src_key_name  Name of the existing object. 
    dst_bucket_name Bucket to which the object is being copied. 
    dst_key_name  The name of the new object. 
    metadata   A dict containing new metadata that you want 
         to associate with this object. If this is None 
         the metadata of the original object will be 
         copied to the new object. 
    preserve_acl  If True, the ACL from the original object 
         will be copied to the new object. If False 
         the new object will have the default ACL. 
    """ 
    s3 = boto.connect_s3() 
    bucket = s3.lookup(src_bucket_name) 

    # Lookup the existing object in S3 
    key = bucket.lookup(src_key_name) 

    # Copy the key back on to itself, with new metadata 
    return key.copy(dst_bucket_name, dst_key_name, 
        metadata=metadata, preserve_acl=preserve_acl) 
0

No hay un método directo para cambiar el nombre del archivo en S3. lo que tienes que hacer es copiar el archivo existente con un nuevo nombre (simplemente establece la clave de destino) y eliminar el anterior. Gracias

Cuestiones relacionadas