Boto3: Docs: S3 put_object Body= can be a file-like object, not just bytes

Created on 5 Feb 2016  路  2Comments  路  Source: boto/boto3

In the documentation for put_object, Boto3 docs say that Body is simply:

Body (bytes) -- Object data.

and give the example:

Body=b'bytes',

Empirically, though, a Python file-like object works just fine. And the automated tests depend on this functionality, so it's probably not going away.

It would be nice if the documentation reflected that Body didn't have to be just bytes.

documentation

Most helpful comment

If you reached this page like me and found nothing on StackOverflow, you can use normal strings as the parameter to create text files. Here's a sample HTML one:

response = s3_client.put_object(
    Bucket='your-s3-bucket-name',
    Body='a big ole string, or html tags like <h1>Yooo</h1>',
    Key='folder/path/index.html',
    ServerSideEncryption='AES256'
)

All 2 comments

Good catch.

Documentation is mostly auto-generated from upstream. We will see what we can do here.

If you reached this page like me and found nothing on StackOverflow, you can use normal strings as the parameter to create text files. Here's a sample HTML one:

response = s3_client.put_object(
    Bucket='your-s3-bucket-name',
    Body='a big ole string, or html tags like <h1>Yooo</h1>',
    Key='folder/path/index.html',
    ServerSideEncryption='AES256'
)
Was this page helpful?
0 / 5 - 0 ratings