We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents c43e236 + cb717fe commit 3a285f7Copy full SHA for 3a285f7
imgurpython/client.py
@@ -580,18 +580,20 @@ def get_image(self, image_id):
580
return Image(image)
581
582
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):
587
if not config:
588
config = dict()
589
- fd = open(path, 'rb')
590
contents = fd.read()
591
b64 = base64.b64encode(contents)
592
data = {
593
'image': b64,
594
'type': 'base64',
595
}
596
data.update({meta: config[meta] for meta in set(self.allowed_image_fields).intersection(config.keys())})
- fd.close()
597
598
return self.make_request('POST', 'upload', data, anon)
599
0 commit comments