title: TypeError: expected string or bytes-like object - how to copy files to an S3 bucket using the code provided in AWS's documentation
body: <p><a href="https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html" rel="nofollow noreferrer">https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html</a></p>
  
  <p>Using the code provided in the documentation, I'm trying to iterate through parent_dir, and if there's a zip file, then I want to copy it to my S3 bucket. </p>
  
  <p>I tried both</p>
  
  <pre><code>    try:
          response = s3_client.upload_file(file_name, bucket, object_name)
      except ClientError as e:
          logging.error(e)
          return False
      return True
  </code></pre>
  
  <p>and</p>
  
  <pre><code>s3 = boto3.client('s3')
  with open("FILE_NAME", "rb") as f:
      s3.upload_fileobj(f, "BUCKET_NAME", "OBJECT_NAME")
  </code></pre>
  
  <p>but both of them gave the same error. </p>
  
  <pre><code>    s3_client = boto3.client(
          's3',
          aws_access_key_id='MY_KEY_ID',
          aws_secret_access_key='MY_ACCESS_KEY'
      )
  
      session = boto3.Session(
          aws_access_key_id='MY_KEY_ID',
          aws_secret_access_key='MY_ACCESS_KEY',
      )
  
      s3 = session.resource('s3')
      bucket = s3.Bucket('MY_URL')
  </code></pre>
  
  <pre><code>    for file in os.listdir(parent_dir):
          if object_name is None:
              object_name = file
  
          if file.endswith('.zip'):
              with open(file, "rb") as f:
                  s3_client.upload_fileobj(f, bucket, object_name)
  </code></pre>
  
  <p><code>TypeError: expected string or bytes-like object</code></p>