I am trying to upload an xls file to s3 using boto3 and python 3.6. I need to be able to upload from an object in memory not disk.
ep = 's3test.xlsx'
portfolio_binary = open(ep, "rb").read()
s3_client.put_object(Body=portfolio_binary, Bucket='test', Key='test/test/test.xlsx')
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Body, value: <class '__main__.portfolio_object'>, type: <class 'type'>, valid types: <class 'bytes'>, <class 'bytearray'>, file-like object
Here's some easier code for you:
import boto3
client = boto3.client('s3')
client.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.