Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda