Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a285f7

Browse filesBrowse 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
Copy full SHA for 3a285f7

File tree

Expand file treeCollapse file tree

1 file changed

+4
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-2
lines changed
Open diff view settings
Collapse file

‎imgurpython/client.py‎

Copy file name to clipboardExpand all lines: imgurpython/client.py
+4-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.