S3 - Allow uploads using a PUT request without content-type (#3699)

This commit is contained in:
Bert Blommers 2021-08-28 06:10:16 +01:00 committed by GitHub
parent 3d584a30a1
commit 684cafa2b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View File

@ -1187,10 +1187,17 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
else:
# Flask server
body = request.data
# when the data is being passed as a file
if request.files and not body:
for _, value in request.files.items():
body = value.stream.read()
if not body:
# when the data is being passed as a file
if request.files:
for _, value in request.files.items():
body = value.stream.read()
elif hasattr(request, "form"):
# Body comes through as part of the form, if no content-type is set on the PUT-request
# form = ImmutableMultiDict([('some data 123 321', '')])
form = request.form
for k, _ in form.items():
body = k
if body is None:
body = b""

View File

@ -5186,6 +5186,22 @@ def test_object_headers():
res.should.have.key("BucketKeyEnabled")
if settings.TEST_SERVER_MODE:
@mock_s3
def test_upload_data_without_content_type():
bucket = "mybucket"
s3 = boto3.client("s3")
s3.create_bucket(Bucket=bucket)
data_input = b"some data 123 321"
req = requests.put("http://localhost:5000/mybucket/test.txt", data=data_input)
req.status_code.should.equal(200)
res = s3.get_object(Bucket=bucket, Key="test.txt")
data = res["Body"].read()
assert data == data_input
@mock_s3
def test_get_object_versions_with_prefix():
bucket_name = "testbucket-3113"