Upload image to S3 from memory

See here for the original answer.

I created an issue on the dataframe_image repository asking this question to the library author, and below is my implementation of his suggestion:

import boto3
import dataframe_image as dfi
from io import BytesIO

# create the buffer in which to store the generated image
png_io = BytesIO()

# assuming that your dataframe is stored as `df` variable
df.dfi.export(png_io)

# create the boto3 client and upload the BytesIO directly;
# create your client in whatever way works for you
session = boto3.session.Session(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name=region_name)
s3_client = session.client('s3')
s3_client.upload_fileobj(png_io, 'your_destination_folder/your_destination_file')

For more information, check this TechOverflow post and this StackOverflow post.


Tags

  1. python (Private)
  2. s3 (Private)
  3. pandas (Private)
  4. dataframe (Private)
  5. stack-overflow (Private)
  6. answer (Private)