Skip to content

Commit b9b6146

Browse files
authored
Python: Update presigned_url.py to enable downloading (#6864)
1 parent d5ae5ef commit b9b6146

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

python/example_code/s3/s3_basics/presigned_url.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ def usage_demo():
7070
response = None
7171
if args.action == "get":
7272
response = requests.get(url)
73+
if response.status_code == 200:
74+
with open(args.key.split("/")[-1], 'wb') as object_file:
75+
object_file.write(response.content)
7376
elif args.action == "put":
7477
print("Putting data to the URL.")
7578
try:
76-
with open(args.key, "r") as object_file:
79+
with open(args.key, "rb") as object_file:
7780
object_text = object_file.read()
7881
response = requests.put(url, data=object_text)
7982
except FileNotFoundError:
@@ -83,9 +86,7 @@ def usage_demo():
8386
)
8487

8588
if response is not None:
86-
print("Got response:")
87-
print(f"Status: {response.status_code}")
88-
print(response.text)
89+
print(f"Status: {response.status_code}\nReason: {response.reason}")
8990

9091
print("-" * 88)
9192

0 commit comments

Comments
 (0)