Fix: Support streaming upload from requests. (#3062)
* Fix: Support streaming upload from requests. * [FIX] style. Co-authored-by: Gordon Cassie <gordon.cassie@closingfolders.com>
This commit is contained in:
parent
dcde2570b1
commit
b88f166099
@ -184,6 +184,8 @@ class CallbackResponse(responses.CallbackResponse):
|
||||
body = None
|
||||
elif isinstance(request.body, six.text_type):
|
||||
body = six.BytesIO(six.b(request.body))
|
||||
elif hasattr(request.body, "read"):
|
||||
body = six.BytesIO(request.body.read())
|
||||
else:
|
||||
body = six.BytesIO(request.body)
|
||||
req = Request.from_values(
|
||||
|
@ -1040,6 +1040,22 @@ def test_s3_object_in_public_bucket_using_multiple_presigned_urls():
|
||||
assert response.status_code == 200, "Failed on req number {}".format(i)
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_streaming_upload_from_file_to_presigned_url():
|
||||
s3 = boto3.resource("s3")
|
||||
bucket = s3.Bucket("test-bucket")
|
||||
bucket.create()
|
||||
bucket.put_object(Body=b"ABCD", Key="file.txt")
|
||||
|
||||
params = {"Bucket": "test-bucket", "Key": "file.txt"}
|
||||
presigned_url = boto3.client("s3").generate_presigned_url(
|
||||
"put_object", params, ExpiresIn=900
|
||||
)
|
||||
with open(__file__, "rb") as f:
|
||||
response = requests.get(presigned_url, data=f)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_s3_object_in_private_bucket():
|
||||
s3 = boto3.resource("s3")
|
||||
|
Loading…
Reference in New Issue
Block a user