python - uploading a plot from memory to s3 using matplotlib and boto -


this working script generates plot, saves locally disk, uploads s3 , deletes file:

plt.figure(figsize=(6,6)) plt.plot(x, y, 'bo') plt.savefig('file_location')  conn = boto.s3.connect_to_region(     region_name=aws_region,     aws_access_key_id=aws_access_key_id,     aws_secret_access_key=aws_secret_access_key,     calling_format=boto.s3.connection.ordinarycallingformat()     ) bucket = conn.get_bucket('bucket_name') k = key(bucket) k.key = 'file_name' k.set_contents_from_filename('file_location')  os.remove(file_location) 

what want skip disk writing , upload plot directly memory.

any suggestions how achieve that?

putting together:

img_data = io.bytesio() plt.savefig(img_data, format='png') img_data.seek(0)  s3 = boto3.resource('s3') bucket = s3.bucket(bucket_name) bucket.put_object(body=img_data, contenttype='image/png', key=key) 

thanks @padraic-cunningham , @guyb7 tips!


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -