Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
is there a way to store a file from url into s3's specific folder, not just into the root?

found a way to upload a file from an url into s3 bucket but is there a way to direct it into a specific folder or create a folder?

I get it working to store into s3's root by using the code below

def save_image_s3(self, img_url, img_name):
    """Saves the image in img_url into S3 with the name img_name"""
    conn = boto.connect_s3(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
    bucket = conn.get_bucket(settings.AWS_STORAGE_BUCKET_NAME)
    k = Key(bucket)
    k.key = img_name
    fp = StringIO.StringIO(urllib2.urlopen(img_url).read())
    k.set_contents_from_file(fp)
    return img_name

Again, this does save it into my bucket's root directory but I am not sure how I can direct it to save into an existing folder or make a new folder if folder does not exist

Thanks in advance

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You are very close, you can set k.key to the full "path" in the bucket to your object. For example:

k.key = 'photos/%s' % img_name

This will save it to what you would consider a "folder" named photos. There is no need for the folder itself to be created first, since S3 folders do not actually exist but are implied by the appearance of one or more / appearing within object keys. Do not add / at the beginning.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda