Skip to content

Commit

Permalink
setting ContentType with python magic
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-bell committed Feb 2, 2021
1 parent c82b75f commit 67d3062
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
14 changes: 13 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "s3-loader"
version = "1.1.5"
version = "1.1.6"
description = "wrapper script for uploading files and dirs to s3"
authors = ["phil-bell <[email protected]>"]
license = "GNU General Public License"
Expand All @@ -13,6 +13,7 @@ readme = "README.md"
python = "^3.6.12"
boto3 = "^1.16.63"
typer = "^0.3.2"
python-magic = "^0.4.20"

[tool.poetry.dev-dependencies]
black = {version = "^20.8b1", allow-prereleases = true}
Expand Down
8 changes: 7 additions & 1 deletion s3_loader/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import typer
import boto3
import magic
import pickle
from botocore.exceptions import NoCredentialsError

Expand Down Expand Up @@ -36,7 +37,12 @@ def upload_file(
aws_secret_access_key=creds["secret"],
)
try:
s3.upload_file(local_file, bucket, s3_file)
s3.upload_file(
Filename=local_file,
Bucket=bucket,
Key=s3_file,
ExtraArgs={"ContentType": magic.from_file(local_file, mime=True)},
)
print(f"File uploaded: {s3_file}")
except FileNotFoundError:
print("ERROR: file not found")
Expand Down

0 comments on commit 67d3062

Please sign in to comment.