I currently use the following code to create a binary file that I then directly upload into AWS S3. Now I was told it's possible to write with the csv.writer
directly into the binary mode and avoid the extra step with io.StringIO()
. How does that work?
buffer = io.StringIO()
writer = csv.writer(buffer)
writer.writerow(["a", "b", "c"])
buffer_2 = io.BytesIO(buffer.getvalue().encode())
BUCKET_NAME = 'fbprophet'
OBJECT_NAME = 'blah.csv'
s3.upload_fileobj(buffer_2, BUCKET_NAME, OBJECT_NAME)