title: s3.upload_fileobj gives error a bytes-like object is required
body: <p>My question is inspired by a <a href="https://stackoverflow.com/questions/55404263/what-is-the-fastest-way-to-save-a-large-pandas-dataframe-to-s3">previous SO</a> about this topic: uploading and saving DataFrames as csv files in Amazon Web Services (AWS) S3. Using Python3, I would like to use <code>s3.upload_fileobj</code> – multi-part uploads – to make the data transfer to S3 faster. When I run the code in the accepted answer, I receive an error message : <em>"TypeError: a bytes-like object is required, not 'str' ".</em> .</p>
  
  <p>The answer has recently been upvoted several times. So I think there must be a way to run this code without error in Python3.   </p>
  
  <p>Please find below the code. Let's for ease use a simple DataFrame. In reality this DataFrame is much bigger (at around 500 MB). </p>
  
  <pre><code>import pandas as pd
  import io
  
  df = pd.DataFrame({'A':[1,2,3], 'B':[6,7,8]})
  </code></pre>
  
  <p>The code is the following. I turned it for convenience in a function :</p>
  
  <pre><code>def upload_file(dataframe, bucket, key):
      """dat=DataFrame, bucket=bucket name in AWS S3, key=key name in AWS S3"""
      s3 = boto3.client('s3')
      csv_buffer = io.BytesIO()
      dataframe.to_csv(csv_buffer, compression='gzip')
      s3.upload_fileobj(csv_buffer, bucket, key)
  
  upload_file(df, your-bucket, your-key)
  </code></pre>
  
  <p>Thank you very much for your advices!</p>