S3 - Allow uploads using a PUT request without content-type (#3699)
This commit is contained in:
parent
3d584a30a1
commit
684cafa2b8
@ -1187,10 +1187,17 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
else:
|
else:
|
||||||
# Flask server
|
# Flask server
|
||||||
body = request.data
|
body = request.data
|
||||||
# when the data is being passed as a file
|
if not body:
|
||||||
if request.files and not body:
|
# when the data is being passed as a file
|
||||||
for _, value in request.files.items():
|
if request.files:
|
||||||
body = value.stream.read()
|
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:
|
if body is None:
|
||||||
body = b""
|
body = b""
|
||||||
|
@ -5186,6 +5186,22 @@ def test_object_headers():
|
|||||||
res.should.have.key("BucketKeyEnabled")
|
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
|
@mock_s3
|
||||||
def test_get_object_versions_with_prefix():
|
def test_get_object_versions_with_prefix():
|
||||||
bucket_name = "testbucket-3113"
|
bucket_name = "testbucket-3113"
|
||||||
|
Loading…
Reference in New Issue
Block a user