Skip to content

Instantly share code, notes, and snippets.

@anna-geller
Created August 1, 2021 12:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anna-geller/5644de2c962f30c5d86ea3ab91b3a486 to your computer and use it in GitHub Desktop.
Save anna-geller/5644de2c962f30c5d86ea3ab91b3a486 to your computer and use it in GitHub Desktop.
import boto3
s3 = boto3.client("s3")
bucket_name = "annageller"
s3_object = "sales/customers.csv"
local_file_path = f"/Users/annageller/Desktop/datasets/{s3_object}"
# Uploading without specifying content type
s3.upload_file(
local_file_path,
bucket_name,
s3_object
)
response = s3.head_object(Bucket=bucket_name, Key=s3_object)
print(response["ResponseMetadata"]["HTTPHeaders"]["content-type"]) # binary/octet-stream
# Uploading with specifying content type: text/csv
s3.upload_file(
local_file_path,
bucket_name,
s3_object,
ExtraArgs={'ContentType': 'text/csv'}
)
response = s3.head_object(Bucket=bucket_name, Key=s3_object)
print(response["ResponseMetadata"]["HTTPHeaders"]["content-type"]) # text/csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment