Skip to content

Commit 3a285f7

Browse files
author
Jacob Greenleaf
committed
Merge pull request Imgur#53 from khazhyk/master
Allow uploading file-like objects, allowing uploading of BytesIO/etc.
2 parents c43e236 + cb717fe commit 3a285f7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

imgurpython/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,18 +580,20 @@ def get_image(self, image_id):
580580
return Image(image)
581581

582582
def upload_from_path(self, path, config=None, anon=True):
583+
with open(path, 'rb') as fd:
584+
self.upload(fd, config, anon)
585+
586+
def upload(self, fd, config=None, anon=True):
583587
if not config:
584588
config = dict()
585589

586-
fd = open(path, 'rb')
587590
contents = fd.read()
588591
b64 = base64.b64encode(contents)
589592
data = {
590593
'image': b64,
591594
'type': 'base64',
592595
}
593596
data.update({meta: config[meta] for meta in set(self.allowed_image_fields).intersection(config.keys())})
594-
fd.close()
595597

596598
return self.make_request('POST', 'upload', data, anon)
597599

0 commit comments

Comments
 (0)