Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use s3 download_file #137

Closed
francophongvu opened this issue Jan 24, 2019 · 2 comments
Closed

how to use s3 download_file #137

francophongvu opened this issue Jan 24, 2019 · 2 comments

Comments

@francophongvu
Copy link

  • Async AWS SDK for Python version: boto3 1.9.49
  • Python version:3.6
  • Operating System: Mac OS

Description

I tried to download file from S3, and I received error:
A Future or coroutine is required

In the documentation, I cannot find how to use the S3 properly except DynamoDB. Is it worth to update the doc ?

What I Did

async def download_files():
    async with aioboto3.resource('s3') as s3:
        await s3.meta.client.download_file(const.bucket_name, 'file/test.txt', '/tmp/test.txt')
        print('file downloaded')

def process():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(download_files())
    loop.close()

process()
@burrbank
Copy link

burrbank commented Jan 30, 2019

I managed to get s3 downloads working with using:

async def download_json(key):
    async with aioboto3.resource('s3') as s3:
        obj = s3.Object(const.bucket, key)
        result = await obj.get()
        result = await result['Body'].read()
    return json.loads(result.decode('utf-8'))['keys']
key = "..."
loop = asyncio.get_event_loop()
loop.run_until_complete(download_json(key))
# loop.close() # I had to skip this line, though I expect that was an issue with jupyter maybe.

@terricain
Copy link
Owner

download_file works like you would expect now, it does not do multipart downloads but that has been requested in #131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants