Skip to content

Commit

Permalink
Adds missing file close logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ebozduman committed Jul 4, 2018
1 parent 53ad4f3 commit cce8f8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
15 changes: 8 additions & 7 deletions examples/put_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@

# Put a file with default content-type.
try:
file_stat = os.stat('my-testfile')
file_data = open('my-testfile', 'rb')
client.put_object('my-bucketname', 'my-objectname', file_data, file_stat.st_size)
with open('my-testfile', 'rb') as file_data:
file_stat = os.stat('my-testfile')
client.put_object('my-bucketname', 'my-objectname',
file_data, file_stat.st_size)
except ResponseError as err:
print(err)

# Put a file with 'application/csv'
try:
file_stat = os.stat('my-testfile.csv')
file_data = open('my-testfile.csv', 'rb')
client.put_object('my-bucketname', 'my-objectname', file_data,
file_stat.st_size, content_type='application/csv')
with open('my-testfile.csv', 'rb') as file_data:
file_stat = os.stat('my-testfile.csv')
client.put_object('my-bucketname', 'my-objectname', file_data,
file_stat.st_size, content_type='application/csv')
except ResponseError as err:
print(err)
9 changes: 4 additions & 5 deletions minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,10 @@ def fput_object(self, bucket_name, object_name, file_path,
"""

# Open file in 'read' mode.
file_data = io.open(file_path, mode='rb')
file_size = os.stat(file_path).st_size

return self.put_object(bucket_name, object_name, file_data, file_size,
content_type, metadata)
with open(file_path, 'rb') as file_data:
file_size = os.stat(file_path).st_size
return self.put_object(bucket_name, object_name, file_data,
file_size, content_type, metadata)

def fget_object(self, bucket_name, object_name, file_path, request_headers=None):
"""
Expand Down

0 comments on commit cce8f8b

Please sign in to comment.