How to upload a file to S3 without creating a temporary local file

前端 未结 10 1700
無奈伤痛
無奈伤痛 2021-01-30 13:49

Is there any feasible way to upload a file which is generated dynamically to amazon s3 directly without first create a local file and then upload to the s3 server? I use python.

10条回答
  •  一向
    一向 (楼主)
    2021-01-30 14:17

    I am having a similar issue, was wondering if there was a final answer, because with my code below , the "starwars.json" keeps on saving locally but I just want to push through each looped .json file into S3 and have no file stored locally.

    for key, value in star_wars_actors.items():
    
    response = requests.get('http:starwarsapi/' + value)
    
    
    
    data = response.json()
    
    
    with open("starwars.json", "w+") as d:
        json.dump(data, d, ensure_ascii=False, indent=4)
    
    
    
    s3.upload_file('starwars.json', 'test-bucket',
                   '%s/%s' % ('test', str(key) + '.json'))
    

提交回复
热议问题