boto3 s3.Object().put() always injects text/plain; charset=utf-8' into ContentType
See original GitHub issuePython 3.5.2, Ubuntu 14.04, moto 0.4.23, boto3 1.3.1.
It seems like moto is injecting ‘text/plain; charset=utf-8’ into the content type of all files when I read them / upload them as below.
def test_direct_s3(self):
bucket_name = '...'
local_path = 'core/bucket_template/index.html'
s3_path = 'testzooga/index.html'
s3 = boto3.resource('s3', verify=False)
with open(local_path, 'rb') as _file:
content_type = mimetypes.guess_type(local_path)
s3.Object(bucket_name, s3_path).put(
ContentType=content_type[0],
Body=_file,
ACL='public-read'
)
print(s3.Object(bucket_name, s3_path).content_type)
# print(s3.Object(bucket_name, s3_path).get())
assert 1 == 0
@mock_s3
def test_mocked_s3(self):
my_bucket = s3.Bucket('my-cool-bucket')
my_bucket.create()
local_path = 'core/bucket_template/index.html'
s3_path = 'testzooga/index.html'
s3 = boto3.resource('s3', verify=False)
with open(local_path, 'rb') as _file:
content_type = mimetypes.guess_type(local_path)
s3.Object(my_bucket.name, s3_path).put(
ContentType=content_type[0],
Body=_file,
ACL='public-read'
)
print(s3.Object(my_bucket.name, s3_path).content_type)
# print(s3.Object(my_bucket.name, s3_path).get())
assert 1 == 0
Will print:
text/html
during the first test as it writes to the un-mocked S3
text/plain; charset=utf-8, text/html
during the second test when writing to the mocked S3
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
S3 — Boto3 Docs 1.26.34 documentation - AWS
Upon receiving this request, Amazon S3 concatenates all the parts in ascending order by part number to create a new object. In the...
Read more >Text files uploaded to S3 are encoded strangely?
You can explicitly set the "Content-Type: text/plain; charset=utf-8", on the file in the S3 console. This will tell S3 to serve as text....
Read more >Quickstart and Tutorial — Python Serverless Microframework ...
In this tutorial, you'll use the chalice command line utility to create and deploy a basic REST API. This quickstart uses Python 3.7,...
Read more >aws_s3_bucket_object | Resources | hashicorp/aws
If you prefer to not have Terraform recreate the object, import the object using aws_s3_object . Provides an S3 object resource.
Read more >cgi — Common Gateway Interface support ... - Python Docs
A CGI script is invoked by an HTTP server, usually to process user input ... print("Content-Type: text/html") # HTML is following print() #...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
i am seeing this in both Python 3 and Python 2
Confirmed fixed with https://github.com/spulec/moto/pull/2795